threaddemo1.java

来自「为成会员而传的」· Java 代码 · 共 55 行

JAVA
55
字号
/*
 * ThreadTest.java
 *
 * Created on 2008年3月22日, 下午6:56
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
class ThreadTest extends Thread {
    
    /** Creates a new instance of ThreadTest */
    public ThreadTest() {
    }
    public void run()
    {
        for(int i=1;i<=10;i++)
        {
            System.out.println(Thread.currentThread().getName()+"is running");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            
        }
    }
}
public class ThreadDemo1
{
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       ThreadTest t=new ThreadTest();
       t.start();
       for(int i=1;i<=10;i++)
       {
           System.out.println("main thread is running");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
       }
    }
    
}

⌨️ 快捷键说明

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