title: Why am I getting IllegalMonitorStateException?
body: <p>I get the following Exception being thrown when I try to unlock an object.</p>
  
  <pre><code>Exception in thread "Thread-1" java.lang.IllegalMonitorStateException
      at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(Unknown Source)
      at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(Unknown Source)
      at java.util.concurrent.locks.ReentrantLock.unlock(Unknown Source)
      at Pipe.unlock(Pipe.java:21)
      at Station.doWork(Station.java:81)
      at Station.run(Station.java:66)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>All that Pipe.unlock is doing is the following:</p>
  
  <pre><code>public void unlock(){
     accessLock.unlock();
  }
  </code></pre>
  
  <p>Where accessLock is an ReentrantLock</p>
  
  <p>Do you know where the issue could be?</p>
  
  <p>EDIT:</p>
  
  <p>This is the run method in Station</p>
  
  <pre><code>if(Pipes[inConnection].accessLock.tryLock()){
      System.out.println("Station "+ StationNumber+": granted access to pipe "+inConnection+".");
  
  //This is just a way for me to keep track if both pipes have been granted
              if(connected&lt;0)
                  connected=inConnection;
              else
                  connected+=inConnection;
  }
  
  
  if(Pipes[outConnection].accessLock.tryLock()){
              System.out.println("Station "+ StationNumber+": granted access to pipe "+outConnection+".");
  
      //This is just a way for me to keep track if both pipes have been granted
      if(connected&lt;0)
          connected=outConnection;
      else
          connected+=outConnection;   
  }
  
  
          doWork();
  </code></pre>
  
  <p>While this is the doWork method:</p>
  
  <pre><code>private void doWork() {
      if(connected==inConnection+outConnection){
          System.out.println("Station "+StationNumber+": successfully flows "+inConnection+".");
          System.out.println("Station "+StationNumber+": successfully flows "+outConnection+".");
  
          Pipes[inConnection].unlock();
          System.out.println("Station "+StationNumber+": released access to pipe "+inConnection+".");
  
          Pipes[outConnection].unlock();
          System.out.println("Station "+StationNumber+": released access to pipe "+outConnection+".");
  
          try {
              Thread.sleep(rand.nextInt(200));
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          WorkLoad--;
      }else if(connected &gt;=0 ){
          Pipes[connected].unlock();
          System.out.println("Station "+StationNumber+": released access to pipe "+connected);
  
      }
  
      connected=-1;
  }
  </code></pre>