I'm trying to create a ThreadPoolExecutor:
// Thingy implements Delayed and Runnable
ExecutorService executor = new ThreadPoolExecutor(1, 1, 0l, TimeUnit.SECONDS, new DelayQueue<Thingy>());
The compiler is saying "cannot find symbol":
symbol : constructor ThreadPoolExecutor(int,int,long,java.util.concurrent.TimeUnit,java.util.concurrent.DelayQueue<Thingy>)
but I don't understand — DelayQueue
implements BlockingQueue
, so shouldn't I be able to use this constructor?
This is a generics problem. You can't use DelayQueue<Thingy>
, it has to be DelayQueue<Runnable>
as the ThreadPoolExecutor
constructor is not declared to accept queues of sub-types of Runnable
.