Reputation: 363
Here is what I want to do:
There are many threads start at any time, and each thread will run about 5s. When one thread is running, others must wait. And when the running thread ends, the newest thread start to run and other waiting threads just stop. Of course, there will be situations: when one thread start, there's no other thread.
I tried to use FutureTask, but failed. It seems too complex for me. Can anyone give me some idea?
Upvotes: 2
Views: 180
Reputation: 12306
you might want to take a look at single-threaded executor, which will take your tasks from task queue and invoke them sequentially.
it is more convenient to use this class if you will decide later to add some concurrency
Upvotes: 5