我正在尝试创建一个 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
,所以我不应该能够使用这个构造函数 http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html#ThreadPoolExecutor%28int,%20int,%20long,%20java.util.concurrent.TimeUnit,%20java.util.concurrent.BlockingQueue%29?
这是一个泛型问题。你不能使用DelayQueue<Thingy>
, 它一定要是DelayQueue<Runnable>
as the ThreadPoolExecutor
构造函数未声明为接受子类型的队列Runnable
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)