220 |
|
* a newSingleThreadScheduledExecutor successfully runs delayed task |
221 |
|
*/ |
222 |
|
public void testNewSingleThreadScheduledExecutor() throws Exception { |
223 |
< |
try { |
224 |
< |
TrackedCallable callable = new TrackedCallable(); |
225 |
< |
ScheduledExecutorService p1 = Executors.newSingleThreadScheduledExecutor(); |
226 |
< |
Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
227 |
< |
assertFalse(callable.done); |
228 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
229 |
< |
assertTrue(callable.done); |
230 |
< |
assertEquals(Boolean.TRUE, f.get()); |
231 |
< |
joinPool(p1); |
232 |
< |
} catch (RejectedExecutionException e) {} |
223 |
> |
TrackedCallable callable = new TrackedCallable(); |
224 |
> |
ScheduledExecutorService p1 = Executors.newSingleThreadScheduledExecutor(); |
225 |
> |
Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
226 |
> |
assertFalse(callable.done); |
227 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
228 |
> |
assertTrue(callable.done); |
229 |
> |
assertEquals(Boolean.TRUE, f.get()); |
230 |
> |
joinPool(p1); |
231 |
|
} |
232 |
|
|
233 |
|
/** |
234 |
|
* a newScheduledThreadPool successfully runs delayed task |
235 |
|
*/ |
236 |
|
public void testnewScheduledThreadPool() throws Exception { |
237 |
< |
try { |
238 |
< |
TrackedCallable callable = new TrackedCallable(); |
239 |
< |
ScheduledExecutorService p1 = Executors.newScheduledThreadPool(2); |
240 |
< |
Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
241 |
< |
assertFalse(callable.done); |
242 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
243 |
< |
assertTrue(callable.done); |
244 |
< |
assertEquals(Boolean.TRUE, f.get()); |
247 |
< |
joinPool(p1); |
248 |
< |
} catch (RejectedExecutionException e) {} |
237 |
> |
TrackedCallable callable = new TrackedCallable(); |
238 |
> |
ScheduledExecutorService p1 = Executors.newScheduledThreadPool(2); |
239 |
> |
Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
240 |
> |
assertFalse(callable.done); |
241 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
242 |
> |
assertTrue(callable.done); |
243 |
> |
assertEquals(Boolean.TRUE, f.get()); |
244 |
> |
joinPool(p1); |
245 |
|
} |
246 |
|
|
247 |
|
/** |
248 |
< |
* an unconfigurable newScheduledThreadPool successfully runs delayed task |
248 |
> |
* an unconfigurable newScheduledThreadPool successfully runs delayed task |
249 |
|
*/ |
250 |
|
public void testunconfigurableScheduledExecutorService() throws Exception { |
251 |
< |
try { |
252 |
< |
TrackedCallable callable = new TrackedCallable(); |
253 |
< |
ScheduledExecutorService p1 = Executors.unconfigurableScheduledExecutorService(Executors.newScheduledThreadPool(2)); |
254 |
< |
Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
255 |
< |
assertFalse(callable.done); |
256 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
257 |
< |
assertTrue(callable.done); |
258 |
< |
assertEquals(Boolean.TRUE, f.get()); |
263 |
< |
joinPool(p1); |
264 |
< |
} catch (RejectedExecutionException e) {} |
251 |
> |
TrackedCallable callable = new TrackedCallable(); |
252 |
> |
ScheduledExecutorService p1 = Executors.unconfigurableScheduledExecutorService(Executors.newScheduledThreadPool(2)); |
253 |
> |
Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
254 |
> |
assertFalse(callable.done); |
255 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
256 |
> |
assertTrue(callable.done); |
257 |
> |
assertEquals(Boolean.TRUE, f.get()); |
258 |
> |
joinPool(p1); |
259 |
|
} |
260 |
|
|
261 |
|
/** |