1   import java.lang.Thread;
2   import java.io.RandomAccessFile;
3   import java.nio.channels.FileChannel;
4   import java.nio.channels.FileLock;
5   
6   /*
7    * http://bugs.sun.com/view_bug.do?bug_id=6543863
8    */
9   public class T {
10      public static void main(String[] args) throws Exception {
11          final RandomAccessFile file = new RandomAccessFile("foo", "r");
12          final FileChannel channel = file.getChannel();
13  
14          // thrd 1
15          Thread thrd1 = new Thread() {
16              public void run() {
17                  try {
18                      file.close();
19                  } catch (Exception ex) {
20  
21                  }
22              }
23          };
24          thrd1.start();
25  
26          // thrd 2
27          Thread thrd2 = new Thread() {
28              public void run() {
29                  try {
30                      FileLock lock = channel.lock();
31                      lock.release();
32                  } catch (Exception ex) {
33      
34                  }
35              }
36          };
37          thrd2.start();
38      }
39  }
40  
41