Thread pool to control start or threads

S

sakcee

Hi

I want to create a threadpool, to which I can sumbit all jobs but they
start concurantly or by given a signal runAll.
is it possiblt by Executors or ExecuteService etc

thanks
 
E

Eric Sosman

Hi

I want to create a threadpool, to which I can sumbit all jobs but they
start concurantly or by given a signal runAll.
is it possiblt by Executors or ExecuteService etc

One easy way to do this would be to "submit" the jobs
by putting them in some kind of Collection, and just let
them sit there. Then when you want them all to start, you
submit one "StarterGun" job to the thread pool: It just
grabs all the jobs out of your Collection, submits them,
and finishes.

An advantage of this technique is that you can use
the same thread pool for multiple "heats" of different
sets of jobs. Just build another Collection and submit
another StarterGun, and off they go.
 
D

Daniel Pitts

Hi

I want to create a threadpool, to which I can sumbit all jobs but they
start concurantly or by given a signal runAll.
is it possiblt by Executors or ExecuteService etc

thanks

Why do you want all the jobs to start concurrently? Why not let them
start as you add them?

It wouldn't be possible if you had more threads than CPU cores
anyway... They start when the CPU schedules them first.

If you need to synchronize a lot of things, look into the
CyclicBarrier class.
 
S

sakcee

Thanks for info, I kinda did same as both of above ppl said, created a
collection from which threadpool reads. but before starting all jobs
wait
on cyclic barrier and when barrier trips , all are go.
well my manager wants it written that way. if a job is short enuff it
might finish in its time slice and also with letting them start in a
loop or with submit, there might
be some implicit small sequencing that is introduced. I am sure it
does not matter and submitting inside a loop is fine.


thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top