问个Java多线程的问题,麻烦大家了
[code=Jav]
public class Example1 {
public static void main(String args[])
{
TestThread2 testthread2 = new TestThread2();
TestThread1 testthread = new TestThread1();
new Thread(testthread2).start();
new Thread(testthread).start();
}
}
class TestThread1 implements Runnable
{
public void run()
{
for (int i = 0; i < 10; i ++)
{
System.out.println("TestThread1 在运行");
}
}
}
class TestThread2 implements Runnable
{
public void run()
{
for (int i = 0; i < 10; i ++)
{
System.out.println("TestThread2 在运行");
}
}
}
[/code]
我写了一段多线程example,可以运行出来和我预期的不一样,以下是我的运行结果
TestThread2 在运行
TestThread2 在运行
TestThread2 在运行
TestThread2 在运行
TestThread2 在运行
TestThread2 在运行
TestThread2 在运行
TestThread2 在运行
TestThread2 在运行
TestThread2 在运行
TestThread1 在运行
TestThread1 在运行
TestThread1 在运行
TestThread1 在运行
TestThread1 在运行
TestThread1 在运行
TestThread1 在运行
TestThread1 在运行
TestThread1 在运行
TestThread1 在运行
而且期望的结果是:
TestThread2 在运行
TestThread1 在运行
交替出现
请问我写的地方有什么不对么?