70 // Now try to shutdown the executor service while tasks
71 // are blocked. This should cause the tasks to be
72 // interrupted.
73 executor.shutdownNow();
74 if (! executor.awaitTermination(5, TimeUnit.SECONDS))
75 throw new Error("Executor stuck");
76
77 // Wait for the invocation thread to complete.
78 thread.join(1000);
79 if (thread.isAlive()) {
80 thread.interrupt();
81 thread.join(1000);
82 throw new Error("invokeAll stuck");
83 }
84 }
85
86 /**
87 * A helper class with a method to wait for a notification.
88 *
89 * The notification is received via the
90 * <code>sendNotification</code> method.
91 */
92 static class NotificationReceiver {
93 /** Has the notifiee been notified? */
94 boolean notified = false;
95
96 /**
97 * Notify the notification receiver.
98 */
99 public synchronized void sendNotification() {
100 notified = true;
101 notifyAll();
102 }
103
104 /**
105 * Waits until a notification has been received.
106 *
107 * @throws InterruptedException if the wait is interrupted
108 */
109 public synchronized void waitForNotification()
110 throws InterruptedException {
|
70 // Now try to shutdown the executor service while tasks
71 // are blocked. This should cause the tasks to be
72 // interrupted.
73 executor.shutdownNow();
74 if (! executor.awaitTermination(5, TimeUnit.SECONDS))
75 throw new Error("Executor stuck");
76
77 // Wait for the invocation thread to complete.
78 thread.join(1000);
79 if (thread.isAlive()) {
80 thread.interrupt();
81 thread.join(1000);
82 throw new Error("invokeAll stuck");
83 }
84 }
85
86 /**
87 * A helper class with a method to wait for a notification.
88 *
89 * The notification is received via the
90 * {@code sendNotification} method.
91 */
92 static class NotificationReceiver {
93 /** Has the notifiee been notified? */
94 boolean notified = false;
95
96 /**
97 * Notify the notification receiver.
98 */
99 public synchronized void sendNotification() {
100 notified = true;
101 notifyAll();
102 }
103
104 /**
105 * Waits until a notification has been received.
106 *
107 * @throws InterruptedException if the wait is interrupted
108 */
109 public synchronized void waitForNotification()
110 throws InterruptedException {
|