public static void main(String[] args) throws Exception {
Thread threadOne = new Thread(new Runnable() {
public void run() {
methodOne();
}
});
Thread threadTwo = new Thread(new Runnable() {
public void run() {
methodTwo();
}
});
// 执行线程
threadOne.start();
threadTwo.start();
Thread.sleep(1000);
}
public static void methodOne() {
System.out.println("Method one is running!");
}
public static void methodTwo() {
System.out.println("Method two is running!");
}
Java 线程实现两个方法同时运行
最新推荐文章于 2023-10-12 17:32:45 发布