| Author |
Under what conditions does the ScheduledExecutorService start the task on new threads (JDK 5)
|
Robin Sharma
Ranch Hand
Joined: Aug 24, 2005
Posts: 76
|
|
Howdy!
I'm playing around with the ScheduledExecutorService scheduler. In the code i first init the scheduler with a fixed thread pool size and then pass it a simple task which keeps refreshing a shared list with new data, periodically. At random, the task might throw a runtime exception, in which case the scheduler should start a new thread, but i don't see it doing that. So, how do i simulate this scenario? I'm running this code on a single CPU m/c, using JDK 1.5.
I just get the following log messages and then nothing happens:
[18:41:45,150] Using a pool size of: 1
[18:41:45,160] Original list... [33, 39, 4, 82, 22]
[18:41:45,160] Starting scheduler...
[18:41:45,160] Setting shutdown hook to cleanup thread pools...
[18:41:49,156] pool-1-thread-1 > Refreshing list with new data: [25, 42, 73, 17, 17]
[18:41:49,166] pool-1-thread-1 > zzzZZZ, gotta sleep before updating...
[18:41:51,169] Oops, gotta throw an exception
Thanks.
|
DW
There is always a bug :-)
|
 |
Nitesh Kant
Bartender
Joined: Feb 25, 2007
Posts: 1638
|
|
|
Since your task ended up with an exception, it will not be executed anymore.
|
apigee, a better way to API!
|
 |
Max Galushka
Greenhorn
Joined: Mar 29, 2007
Posts: 8
|
|
Just don't throw an exception inside your task
|
Thanks.
Maxim Galushka
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14669
|
|
Why not catch any exceptions here ? If you catch and log them, the executor will not be terminated.
|
[My Blog]
All roads lead to JavaRanch
|
 |
 |
|
|
subject: Under what conditions does the ScheduledExecutorService start the task on new threads (JDK 5)
|
|
|