j_thread.java.bak

来自「一个十分好的java基础学习的课件」· BAK 代码 · 共 53 行

BAK
53
字号
// ////////////////////////////////////////////////////////
// 
// J_Thread.java
// 
// Created by Jun-Hai Yong,    on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
//      Demonstrating the Thread class.
// ////////////////////////////////////////////////////////
// Using this example, please explicitly refer to the book:
//     Jun-Hai Yong. Programming in Java. 
//     Beijing: Tsinghua University Press, 2004.
// 使用本例子,请注明引用:
//     雍俊海. Java 程序设计. 北京: 清华大学出版社, 2004.
// Please note that the author and publisher make no 
// warranty of any kind on the examples provided.
// ////////////////////////////////////////////////////////

public class J_Thread extends Thread
{
    private int m_threadID;

    public J_Thread(int i)
    {
        System.out.println("Create thread: " + i);
        m_threadID=i;
    } // End of method: J_Thread
    
    public void run( )
    {
        for(int i=0; i<3; i++)
        {
            System.out.println(" Running thread: " + m_threadID);
            try
            {
                Thread.sleep((int)(Math.random( ) * 1000));
            }
            catch ( InterruptedException ex )
            {
                System.err.println(ex.toString( ));
            } // End of try/catch structure
        } // End of loop: for
    } // End of method: run
    
    public static void main( String args[] )
    { 
        new J_Thread(1).start( );
        new J_Thread(2).start( );
        System.out.println("End of main");
    } // End of method: main

}  // End of class: J_Thread

⌨️ 快捷键说明

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