でタスクを渡すExecutorService
(または atm のサブクラス) があります。ThreadPoolExecutorService
submit(Runnable r)
実行中に同じタスクが (再) 送信される場合があり、最初の送信が完了するまで 2 番目の送信を待ちたいと思います。つまり、キューに入れました。それを行うにはどうすればよいでしょうか?送信されたタスクが既に実行されている場合にのみキューに入れ、それ以外の場合は直接実行する必要があります。
返さFuture<>
れた s は、タスクをキャンセルするために使用されることがあります。
このようなもの;
Runnable r = new LengthyRunnable();
Future<?> f1 = submit(r); //should start to run
Future<?> f2 = submit(r); //should be queued and wait for f1
Future<?> f3 = submit(r); //in case f1 hasnt finished, and f2 is queued, should remove f2 from the queue and take it's place
私は ThreadPoolExecutorService をサブクラス化し、 beforeExecute と afterExecute を使用してタスクを追跡していますが、難しくなっています... a 以外のものを使用する必要がありThreadPoolExecutorService
ますか?