• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Under what conditions does the ScheduledExecutorService start the task on new threads (JDK 5)

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since your task ended up with an exception, it will not be executed anymore.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just don't throw an exception inside your task
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why not catch any exceptions here ? If you catch and log them, the executor will not be terminated.
reply
    Bookmark Topic Watch Topic
  • New Topic