⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example9_5.java

📁 《Java程序设计与应用》-张仕斌-源程序 《Java程序设计与应用》-张仕斌-源程序
💻 JAVA
字号:
/*
 * Example9_5.java
 *
 * Created on 2006年10月12日, 上午11:40
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package example9_5;

/**
 *
 * @author Administrator
 */
public class Example9_5 implements Runnable{
    
    /** Creates a new instance of Example9_5 */
    public Example9_5() {
    }
    
    /**
     * @param args the command line arguments
     */
    public void run() {
		try{
			int sleepTime=(int)(Math.random()*100);  //产生随机数字
			//让其休眠一定时间,时间又上面sleepTime决定
			Thread.currentThread().sleep(sleepTime);  
				System.out.println(Thread.currentThread().getName()+"睡了 "+sleepTime);
		}
		//由于线程在休眠可能被中断,所以调用sleep方法的时候需要捕捉异常
		catch(InterruptedException ie){ie.printStackTrace();} 
	}
	public static void main(String[] args){
		Thread t1=new Thread(new Example9_5());
		Thread t2=new Thread(new Example9_5());
		Thread t3=new Thread(new Example9_5());
		t1.start();t2.start();t3.start();
	}

    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -