jaxp/src/share/classes/com/sun/org/apache/xml/internal/utils/ThreadControllerWrapper.java
equal
deleted
inserted
replaced
51 */ |
51 */ |
52 public static class ThreadController |
52 public static class ThreadController |
53 { |
53 { |
54 |
54 |
55 /** |
55 /** |
56 * Will get a thread from the pool, execute the task |
56 * This class was introduced as a fix for CR 6607339. |
|
57 */ |
|
58 final class SafeThread extends Thread { |
|
59 private volatile boolean ran = false; |
|
60 |
|
61 public SafeThread(Runnable target) { |
|
62 super(target); |
|
63 } |
|
64 |
|
65 public final void run() { |
|
66 if (Thread.currentThread() != this) { |
|
67 throw new IllegalStateException("The run() method in a" |
|
68 + " SafeThread cannot be called from another thread."); |
|
69 } |
|
70 synchronized (this) { |
|
71 if (!ran) { |
|
72 ran = true; |
|
73 } |
|
74 else { |
|
75 throw new IllegalStateException("The run() method in a" |
|
76 + " SafeThread cannot be called more than once."); |
|
77 } |
|
78 } |
|
79 super.run(); |
|
80 } |
|
81 } |
|
82 |
|
83 /** |
|
84 * Will get a thread from the pool, execute the task |
57 * and return the thread to the pool. |
85 * and return the thread to the pool. |
58 * |
86 * |
59 * The return value is used only to wait for completion |
87 * The return value is used only to wait for completion |
60 * |
88 * |
61 * |
89 * |
66 * to wait for completion |
94 * to wait for completion |
67 */ |
95 */ |
68 public Thread run(Runnable task, int priority) |
96 public Thread run(Runnable task, int priority) |
69 { |
97 { |
70 |
98 |
71 Thread t = new Thread(task); |
99 Thread t = new SafeThread(task); |
72 |
100 |
73 t.start(); |
101 t.start(); |
74 |
102 |
75 // if( priority > 0 ) |
103 // if( priority > 0 ) |
76 // t.setPriority( priority ); |
104 // t.setPriority( priority ); |