Java Reference
In-Depth Information
35 System.out.println(getName() + " released lock");
36 }
37
38 private static void printState(Thread t) {
39 System.out.println();
40 System.out.println("State of thread named: " + t.getName());
41 System.out.println("State: " + t.getState());
42 System.out.println("begin trace");
43 for (StackTraceElement ste : t.getStackTrace()) {
44 System.out.println("\t" + ste);
45 }
46 System.out.println("end trace");
47 }
48
49 static class LockOwner extends Thread {
50 public void run() {
51 synchronized (mylock) {
52 System.out.println(getName() + " owns lock");
53 try {
54 ServerSocket ss = new ServerSocket(8080);
55 ss.accept();
56 } catch (Exception e) {
57 e.printStackTrace();
58 }
59 }
60 System.out.println(getName() + " released lock");
61 }
62 }
63 }
Figure 4-12. Output from the blocking example
Search WWH ::




Custom Search