Java多线程一次运行多个方法的最简单方法?
问题描述:
我以前从未使用过多线程,我了解它在基本级别上是什么.我想知道一次执行三个方法的最简单,最有效的方法是什么?
I've never had to multithread before, I understand what it is at a basic level. I'm wondering what would be the simplest and most efficent way to execute three methods at once?
例如
public void test(){
method1();
method2();
method3();
}
基本上我想同时执行1,2和3.我正在寻找对执行此操作有用的任何示例或资源.
Basically I want to execute 1,2 and 3 at the same time. I'm looking for any examples or resources which would be useful for doing this.
谢谢!
答
如果您的三个方法不共享状态,则可以为每个方法增加一个线程.
If your three methods do not share state, you can just spin up a thread for each method.
http://java.sun.com/docs /books/tutorial/essential/concurrency/runthread.html