• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Control threads execution

 
iamiqbal.m Mohiuddin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
iamiqbal.m Mohiuddin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic