[size=large]代码小例子:[/size]
package com.test;
public class ThreadTest2
{
public static void main(String[] args)
{
Thread t = new Thread(new MyThread());
Thread t2 = new Thread(new MyThread2());
t.start();
t2.start();
}
}
class MyThread implements Runnable
{
public void run()
{
for (int i = 0; i < 100; i++)
{
System.out.println("hello:" + i);
}
}
}
class MyThread2 implements Runnable
{
public void run()
{
for (int i = 0; i < 100; i++)
{
System.out.println("welcome:" + i);
}
}
}