title: Using Timeout to avoid deadlock in Java multithreading
body: <p>One of the strategy to avoid deadlock situation in Java Multithreading is using timeout.
  Suppose, one thread has acquired lock on one resource and now waiting for lock on another resource. After certain time period if it can not acquire lock on resource2 then it should stop waiting for lock on resource2. Also it should release lock on resource1. Thus deadlocks will be avoided.</p>
  
  <p>But how to implement it in Java ? How to explicitly "release" lock ? How to define timeout to wait for lock. </p>
  
  <p>What is exact java commands and syntax. Any hello-worldish example please ?</p>