我有
ExecutorService tpool = new ThreadPoolExecutor(5, 50, 5, TimeUnit.MILLISECONDS, new SynchronousQueue<>());
后来int y = tpool.getPoolSize();
但是当我尝试编译时说错误:找不到符号我已经尝试过这些导入(我最初使用.concurrent。*,然后又扔了后两个):
import java.util.concurrent.*;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
出于好奇,我也尝试过boolean x = tpool.isShutdown();
String z = tpool.toString();
long a = tpool.getTaskCount();
int b = tpool.getCorePoolSize();
仅.isShutdown和.getCorepoolSize不会给出编译器错误。我在这里做错什么了吗?
最佳答案
如果您想要这些功能,似乎您正在寻找:
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
...
ThreadPoolExecutor tpool = ..
并不是 :ExecutorService tpool = ...