我如何将参数传递给 ScheduledThreadPoolExecutor?
我有以下代码。你会注意到我已经声明了一个变量'num',它作为一个参数传递给了exampleFunction()。exampleFunction 包含一个 ScheduledThreadPoolExecutor。我希望能够在 public void run() 中使用变量“num”。有什么办法可以做到吗?
class Test {
...
int num;
exampleFunction(num);
...
public void exampleFunction(num) {
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
exec.schedule(new Runnable() {
public void run() {
...do something here...
...something with 'num' here...
...i get an error when i try to use 'num' here
}
}, 10, TimeUnit.SECONDS);
}
}