创建线程:
1、new Thread(new Runnable()).start();2、new Thread()
{
@Override
public void run(){重写该方法}
}.start();
//多线程并发执行调用Thread.start(), 在1还未执行完时,就可执行2
//多线程逐个执行调用Thread.run()
public class Test
{
public static void main(String[] args)
{
new Thread(new Runner1()).start(); //1
new Thread(new Runner2()).start(); //2
}
}
//实现了Runnable接口
class Runner1 implements Runnable
{
public void run()
{
for (int i = 0; i < 1000; i++)
System.out.println("进入Runner1运行状态——————————" + i);
}
}
class Runner2 implements Runnable
{
public void run()
{
for (int i = 0; i < 1000; i++)
System.out.println("进入Runner2运行状态==========" + i);
}
}