线程之间方式区和堆内存共享,栈内存不共享;哪个线程挪用sleep()方式,哪个线程就进入睡眠状态,与哪个工具挪用该方式无关.start()方式的作用是建立一个线程的栈内存,该方式与通俗方式相同,执行完马上销毁.

package test1;

public class RacerRunnable implements Runnable{
    /**
     * 龟兔赛跑多线程
     */
    public String winner;
    public void run() {
    for(int step = 1; step <= 100; step++) {
        if(Thread.currentThread().getName().equals("rabbit") && step % 10 == 0)
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        if(gameOver(step)==true) {
            break;
        }
        System.out.println(Thread.currentThread().getName()+"-->"+step );
    }
}
public boolean gameOver(int step) {
    if(winner != null) {
        return true;
    }else if(step == 100) {
        winner = Thread.currentThread().getName();
        System.out.println("winner-->"+Thread.currentThread().getName());
        return true;
    }else {
        return false;
    }
}
public static void main(String[] args) {
    RacerRunnable racer = new RacerRunnable();
    new Thread(racer, "tortoise").start();
    new Thread(racer, "rabbit").start();
    try {
        Thread.sleep(2000);   //主线程挪用sleep()方式,主线程进入睡眠状态.
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("主线程进入休眠状态!");
}
}