谁能建议我如何将参数传递给线程?
另外,它如何用于匿名类?
你需要将构造函数中的参数传递给Runnable对象:
public class MyRunnable implements Runnable { public MyRunnable(Object parameter) { // store parameter for later user } public void run() { } }
然后调用它:
Runnable r = new MyRunnable(param_value); new Thread(r).start();