• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Process completes and abruptly stops its threads?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I�m having an odd problem with thread pooling.

I have a class (let�s call it Sender) that runs through a variety of data objects, spawning threads to process each one.

I created a class that implements Runnable and, of course, implements the run() method. When it is instantiated, a reference to Sender is passed to it. At the end of run(), it calls a callback method in Sender, giving it identifying information so Sender knows that data object has been processed and can delete it from the database table listing the data objects to process.

Sender creates an ExecutorService using Executors.newFixedThreadPool(). The number is set in a properties file, useful for debugging purposes and for fine-tuning performance and memory issues.

My Runnable objects are instantiated and given to the ExecutorService using the execute() method. After all data objects have been sent, Sender calls the shutdown() method.

All nice and, as far as I can tell, it should work beautifully. But there�s only one problem. The threads (which involve time-consuming tasks and actually spawn child processes- see the thread at https://coderanch.com/t/234068/threads/java/Limit-concurrent-threads-report-successful for more background) never finish processing! However, when I have Sender sleep after executing all the threads, some complete. With enough time- or if I have sender loop, sleeping until threadExecutor.isTerminated()- then all the threads successfully complete processing.

I do not set the threads to be daemon threads. I do not believe the ExecutorService creates them at daemon threads. The main process should continue running until all threads are complete, correct? Any ideas why it�s stopping, and taking the threads with it?

Of course, if I don�t call shutdown() the process NEVER stops, as the ExecutorService waits indefinitely for more tasks to execute.
 
Don't touch me. And dont' touch this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic