This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Cancelling a ScheduledExecutorService Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Cancelling a ScheduledExecutorService" Watch "Cancelling a ScheduledExecutorService" New topic

Cancelling a ScheduledExecutorService

Sam Yim

Joined: Jul 25, 2009
Posts: 17
Hi All,

I'm beginning to expirement w/ the Concurrency package.

I've setup a job to run in an interval using the ScheduledExecutorService.

The return object is ScheduledFuture, which I can use to cancel the scheduled executor service.

However, I'm not sure how to trigger a scheduledFutuer.cancel()...

I've been using 'Control C' on Windows and the kill command in UNIX to kill the job.

But I want to be able to catch these signal to ensure that the current running thread completes before the job/code is killed.

Any ideas?

Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

Look at Runtime#addShutdownHook.

[My Blog]
All roads lead to JavaRanch
Sam Yim

Joined: Jul 25, 2009
Posts: 17
Thanks. Works great.
Consider Paul's rocket mass heater.
subject: Cancelling a ScheduledExecutorService
Similar Threads
Servlet Error
how to delete th file after some specified time.?
Ending a thread from jsp
How to add actionListener to ScheduledExecutorService?
ScheduledExecutorService - Time To Live