Thread queue

B

bob smith

Is there some kind of system in Java where you can put Thread objects on a queue and they get executed in sequence?

Thanks.
 
E

Eric Sosman

Is there some kind of system in Java where you can put Thread objects on a queue and they get executed in sequence?

You could certainly *do* that, daft though it seems. It would
be more usual to put "work units" on a queue and let "worker threads"
take them off and execute them. The java.util.concurrent package
offers various tools for managing concurrent execution -- although
since you say "in sequence," it's not clear that concurrency would
be welcome. I guess you could use Executors.newFixedThreadPool(1)
and submit your tasks to pool's lone worker thread ...
 
A

Arne Vajhøj

Is there some kind of system in Java where you can put Thread objects on a queue and they get executed in sequence?

Call them sequentially instead of starting them??

Arne
 
D

Daniele Futtorovic

Is there some kind of system in Java where you can put Thread objects on a queue and they get executed in sequence?

Thanks.

You're confusing things here. Threads are not things that get executed
(at least not as far as the JVM is concerned). Threads are the things
that *execute*. *Runnable*s or *Callable*s are the things that get executed.

Yes, you can certainly put Runnables or Callables in a queue and have
them be executed sequentially. As mentioned by someone else in this
thread, the java.util.concurrent package is the place you'll want to look.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top