错误:无法找到正确使用的方法的符号(我认为)

huangapple go评论69阅读模式
英文:

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&lt;&gt;());

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 = ...

huangapple
  • 本文由 发表于 2020年10月1日 18:15:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/64153312.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定