example9_1.java

来自「《Java程序设计与应用》-张仕斌-源程序 《Java程序设计与应用》-张仕斌」· Java 代码 · 共 41 行

JAVA
41
字号
/*
 * Example9_1.java
 *
 * Created on 2006年9月21日, 下午2:51
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package example9_1;

/**
 *
 * @author Administrator
 */
public class Example9_1 {
    
    /** Creates a new instance of Example9_1 */
    public Example9_1() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Thread t = Thread.currentThread();  			//获得当前线程
		t.setName("MyThread");   					//给当前线程一个名字
		System.out.println("Current thread is : " + t);   	//打印其主要特征值
    	try {
      		for (int i = 0; i<5; i++) {
        		System.out.println("Sleep time" + i);
        		Thread.sleep(1000); //让当前正在执行的进程进入睡眠状态1000毫秒
     		}
    	}
    	catch(InterruptedException e) {System.out.println("thread error");}

    }
    
}

⌨️ 快捷键说明

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