我正在为我正在进行的项目寻找线程。我希望方法loop1和loop2能够并发运行,因此输出为" 121212121212121212121212121212"。
public class threadTest {
public static void main(String[] args) {
threadOne.start();
threadTwo.start();
}
static Thread threadOne = new Thread() {
public void loop1() {
while(true) {
System.out.println("1");
}
}
};
static Thread threadTwo = new Thread() {
public void loop2() {
while(true) {
System.out.println("2");
}
}
};
}