title: Deadlock with a single thread in java
body: <p>I read that <strong>a single user thread can deadlock with a system thread.</strong>
  My question is , this system thread can be any thread (<strong>not necessarily a java thread</strong>) that is sharing resources with the java thread. E.g. : I/O on 2 files after taking lock on the files.
  So unless the system thread shares the resource with the java thread, it can't create deadlock.
  Is there any other example of the above statement in bold.</p>
  
  <p>Another question:</p>
  
  <p>If there are 2 functions using 2 locks, they should lock in the same order. But is it mandatory to release in the same reverse order. Can the lock release order differ for the 2 functions
  E.g :</p>
  
  <pre><code>function1() {
     try {
      lock1.lock();
      lock2.lock();
     } finally {
       lock2.unlock();
       lock1.unlock();
     }
  }
  
  function2() {
     try {
      lock1.lock();
      lock2.lock();
     } finally {
       lock1.unlock();
       lock2.unlock();
     }
  }
  </code></pre>
  
  <p>Link for reference : <a href="http://book.javanb.com/java-threads-3rd/jthreads3-CHP-3-SECT-8.html" rel="nofollow">if a single user thread deadlocks, a system thread must also be involved</a></p>