英文:
error: cannot find symbol for correctly used methods (I think)
问题
我有以下代码:
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
没有出现编译错误。
我在这里做错了什么吗?
英文:
I have
ExecutorService tpool = new ThreadPoolExecutor(5, 50, 5, TimeUnit.MILLISECONDS, new SynchronousQueue<>());
and later on
int y = tpool.getPoolSize();
but when I attempt to compile it says error: cannot find symbol
I already tried these imports (I used .concurrent.* originally and threw the second two afterwards):
import java.util.concurrent.*;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
Out of curiosity I also tried
boolean x = tpool.isShutdown();
String z = tpool.toString();
long a = tpool.getTaskCount();
int b = tpool.getCorePoolSize();
to which only .isShutdown and .getCorepoolSize did not give a compiler error.
Am I doing something wrong here?
答案1
得分: 0
如果您需要这些功能,似乎您正在寻找:
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
...
ThreadPoolExecutor tpool = ..
而不是:
ExecutorService tpool = ...
英文:
If you want those functionalities, it seems you are looking for :
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
...
ThreadPoolExecutor tpool = ..
and not :
ExecutorService tpool = ...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论