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 Converting threadgroup to executorservice 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 "Converting threadgroup to executorservice" Watch "Converting threadgroup to executorservice" New topic

Converting threadgroup to executorservice

John Vorwald
Ranch Hand

Joined: Sep 26, 2010
Posts: 139
The following code seems to run correctly. The goal is to start four threads on two threadgroups, and then cancel the threads after some calculations are finished, but before the calculation is completed.

I would like to change the code to limit the number of threads submitted at one time.

One approach to limiting the number of thread submitted at one time is to use executor service. But, when I try to convert to executor service, then the code doesn't produce any results.

How should the code be modified to use executor service?
Is there another way to limit the number of threads running at one time? The worker threads are computationally intensive, and would typically run for several minutes.

John Vorwald
Ranch Hand

Joined: Sep 26, 2010
Posts: 139
Somedays I think I know what I'm doing, other days ...

I played with some example codes, and came up with the following implementation of an executor service that has a cancel flag, which is what the previous code was on.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Converting threadgroup to executorservice
Similar Threads
Thread Group
Thread Priority
Why does Thread.sleep know which thread.....
Thread doubt