dig090

Test program showing lock stack dumps.

Mar 2nd, 2012
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package com.mprew.be.service.auto.freecause;
  2.  
  3. public class Foo {
  4.  
  5.     final static Object lock = new Object();
  6.  
  7.     public static void main(String[] args) {
  8.         new Foo().doMain(args);
  9.     }
  10.  
  11.     private void doMain(String[] args) {
  12.         new Thread(new OurRunnable()).start();
  13.         new Thread(new OurRunnable()).start();
  14.         try {
  15.             Thread.sleep(1000);
  16.         } catch (InterruptedException e) {
  17.             e.printStackTrace();
  18.         }
  19.         Object other = new Object();
  20.         synchronized (lock) {
  21.             synchronized (other) {
  22.                 try {
  23.                     other.wait();
  24.                 } catch (InterruptedException e) {
  25.                     e.printStackTrace();
  26.                 }
  27.             }
  28.         }
  29.     }
  30.  
  31.     private static class OurRunnable implements Runnable {
  32.         @Override
  33.         public void run() {
  34.             synchronized (lock) {
  35.                 try {
  36.                     lock.wait(10000);
  37.                 } catch (InterruptedException e) {
  38.                     e.printStackTrace();
  39.                 }
  40.             }
  41.         }
  42.     }
  43. }
Add Comment
Please, Sign In to add comment