创建线程方法二
1. 实现Runnable接口,并实现接口中的run方法;
2. 用Thread的带Thread(Runnable r)构造方法创建线程;
/*
实现runnable接口
*/
class MyRunnable implements Runnable
{
public void run()
{
System.out.println(Thread.currentThread().getName() + "...run");
}
}
class ThreadCreate2
{
public static void main(String[] args)
{
//创建任务
MyRunnable mr = new MyRunnable();
//创建线程
Thread t1 = new Thread(mr);
Thread t2 = new Thread(mr);
Thread t3 = new Thread(mr);
Thread t4 = new Thread(mr);
//开启线程
t1.start();
t2.start();
t3.start();
t4.start();
}
}