wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes How to stop execution of 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 "How to stop execution of ScheduledExecutorService" Watch "How to stop execution of ScheduledExecutorService" New topic
Author

How to stop execution of ScheduledExecutorService

samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
Hello Ranchers
I have developed a code which actually polls the data from a list. Polling needs to happened in multiple threads. For which I am using ScheduledExecutorService. This service will call the logic for data polling after every 2 sec time interval.
I was able to do this. Though when all the data from the list is read and list becomes empty I want to terminate all the threads which are created by ScheduledExecutorService.
Is there any way I can stop this ScheduledExecutorService.
Below is the code which I have written .




Here ThreadPushWorker will have the actual queue in which data is present and I need to terminate the execution of queuePushExecutor once list is empty.
Any help, link will greatly be appreciated.
Thanks
Samir
samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
In addition I as well notice that there is only one thread which is getting created and this is as per the java doc for "newScheduledThreadPool"
Though is there any way I can create multiple threads which will go and execute "ThreadPushWorker" which is my runnable in the current example ?
Thanks
Samir
Nomaan Butt
Ranch Hand

Joined: Oct 19, 2011
Posts: 54
deleted
Nomaan Butt
Ranch Hand

Joined: Oct 19, 2011
Posts: 54
create another scheduled executor service for checking the queue size at regular intervals




samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
Hello Noman,
Thank you so much for the reply. That solved my problem.
Thank you so much.
~Samir
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to stop execution of ScheduledExecutorService
 
Similar Threads
Query about ScheduledThreadPoolExecutor.scheduleAtFixedRate
Reading and writing to a socket concurrently
Last Thread to finish in a multithreaded program
what are daemon threads?
basic concept level question regarding threads