class Thread03
{
public static void main(String[] args)
{
Ticket t = new Ticket();
Thread t1 = new Thread(t);
Thread t2 = new Thread(t);
t1.start();
try{Thread.sleep(10);}catch(Exception e){}
t.setFlag();
t2.start();
如上代码。主线程开启了t1线程之后。停止10毫秒,CPU就一定会切换到t1线程上执行吗?为什么? 也有可能主线程在sleep的10毫秒之间,CPU被切换到执行其他的任务啊
|