展开全部
这个就要用到多线程了,但e69da5e887aa3231313335323631343130323136353331333361323536是即使是多线程,如果你的电脑是单核CPU的,本质上这两个方法还是无法同时执行的,如果你是多个CPU,那么这两个方法就有可能同时执行,注意哦,只是有可能,因此操作系统运行也会有很多程序在运行,操作系统分配资源的时候,未必就能立刻分配给你的程序资源,也就未必能同时执行你的程序。
当然,我们这里主要还是先说说多线程,让两个方法像同时执行一样的效果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!");
}