3

ThreadPoolExecutor を作成しようとしています:

// Thingy implements Delayed and Runnable
ExecutorService executor = new ThreadPoolExecutor(1, 1, 0l, TimeUnit.SECONDS, new DelayQueue<Thingy>());

コンパイラは「シンボルが見つかりません」と言っています:

symbol  : constructor ThreadPoolExecutor(int,int,long,java.util.concurrent.TimeUnit,java.util.concurrent.DelayQueue<Thingy>)

しかし、私は理解していません—DelayQueue実装するので、このコンストラクターBlockingQueueを使用できるべきではありませんか?

4

3 に答える 3

1

RunnableScheduledFutureは実行可能で遅延していますが、にキャストすることはできません BlockingQueue<Runnable>Javaチュートリアルで理由をご覧ください

を見てくださいScheduledThreadPoolExecutor。特定の遅延後に実行するコマンド、または定期的に実行するコマンドをスケジュールできます。

于 2011-08-10T09:11:28.130 に答える