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 Control threads execution 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 "Control threads execution" Watch "Control threads execution" New topic
Author

Control threads execution

iamiqbal.m Mohiuddin
Greenhorn

Joined: May 11, 2006
Posts: 12
We have a simple jsp/struts UI.
Using the UI we can start a batch process by clicking on Run button.
The batch process would fetch records from DB and write to MQ.
We have a threshold value of 30000 records.
When the program retrieves 30000 records we spawn a new thread and pass that list of 30000 records to that thread which does
writing to MQ and the retrieval continues. This process repeats everytime counter reaches 30000 mark.
Now on the UI we are going to have Stop button. When user clicks on stop button the execution of that batch should be stopped. (All the threads that might have spawned should be stopped on clicking of stop).

We have layered architecture with UI (jsp and forms / actions (struts)) and jdbc framework in separate packages.

Any pointers would be highly apprecited.

Thanks in advance,
Iqbal
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Have you thought of using threadpools for your work? Using them you do not have to take the overhead of creating a new thread and you also get cancel(shutdown) functionality for free!
With jdk5 threadpools come along with the jdk. For version before that you can use the backport of the same.


apigee, a better way to API!
iamiqbal.m Mohiuddin
Greenhorn

Joined: May 11, 2006
Posts: 12
Thanks. I appreciate it.

We dont know the number of threads that are going to be created.
Its dynamic based on number os records returned from the database.

I shall explore more on ThreadPool option.
 
 
subject: Control threads execution
 
Similar Threads
Efficient way to calculate the number of threads
Stopping a Thread (where I don't have control of run) Help needed
Design Question (Database Polling)
MaximumThroughput- MltiThreading - Need help
Cancel request mechanism