[英]Java thread run method
In my pregame I have a thread and it's run method must have Queue as input: 在我的赛前,我有一个线程,它的run方法必须以Queue作为输入:
@Override
public void run(Queue q) {
// TODO Auto-generated method stub
A = q.pop();
System.out.println(A * A + "Pop1");
}
And in this case the run method is not an implemented method of my runnable class, so how can I handle this problem? 而且在这种情况下,run方法不是我的runnable类的已实现方法,那么如何处理此问题?
Set the queue as an argument in your constructor. 将队列设置为构造函数中的参数。 Or add it in a setter.
或将其添加到设置器中。 Remove the argument from the run method, but keep it in the method body.
从run方法中删除参数,但将其保留在方法主体中。
You write a second run
method with the right signature for Runnable
. 您为
Runnable
编写了第二个具有正确签名的run
方法。 This one can then get the queue somehow and call the other run
method. 然后,这可以以某种方式获取队列并调用另一种
run
方法。
from the original run() method of the thread , call run(Queue q) method 从线程的原始run()方法开始,调用run(Queue q)方法
@Override
public void run() {
//call the run(Queue q) method from here
}
public void run(Queue q) {
// TODO Auto-generated method stub
A = q.pop();
System.out.println(A * A + "Pop1");
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.