public class Thread_Demo
{
public static void main(String[] args)
{
FirstThread li = new FirstThread("li"); //请问这个有什么作用????
FirstThread wu = new FirstThread("wu");
FirstThread hu = new FirstThread("hu");
Thread thread1 = new Thread(li); //请问这个又有什么作用????
Thread thread2 = new Thread(wu);
Thread thread3 = new Thread(hu);
second_thread thread4 = new second_thread(4);//为什么用继承thread的方式,就不用像上面一样.
thread2.start();
thread3.start();
thread1.start();
thread4.start();
}
}
class FirstThread implements Runnable
{
private String name;
public FirstThread(String name)
{
this.name = name;
}
public void run()
{
while (true)
{
System.out.println("name=" + name);
System.out.println("-----------");
Thread.yield();
}
}
}
class second_thread extends Thread
{
private int num;
public second_thread(int num)
{
this.num = num;
}
public void run()
{
while (true)
{
System.out.println("num=" + num);
System.out.print("**********");
Thread.yield();
}
}
}