的问题是混乱的,但多数民众赞成什么,我想做的事:调用方法
public class Main
{
MyClass instance = new MyClass();
Thread secondThread = new Thread(instance);
public static void main()
{
secondThread.start();
//here i want to call foo(), but be processed by secondThread thread(not the Main thread)
}
}
public class MyClass implements Runnable
{
@Override
public void run()
{
}
public void foo()
{
System.out.println("foo");
}
}
如果我使用“instance.foo();”它将由主线程处理。
是的,我已经从它运行.. –