Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to stop execution of ScheduledExecutorService

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
deleted
 
Nomaan Butt
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
create another scheduled executor service for checking the queue size at regular intervals




 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Noman,
Thank you so much for the reply. That solved my problem.
Thank you so much.
~Samir
 
Danger, 10,000 volts, very electic .... tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic