📄 threethread.java
字号:
package threethread;
/**
* Java语言实验参考程序
* Company 北京师范大学计算机系
* @author 孙一林
* @version 1.0
*/
public class ThreeThread implements Runnable { // 实现Runnable接口
ThreeThread() { // 构造方法
Thread Thread1 = Thread.currentThread(); // 定义线程1
Thread1.setName( "The first main thread" ); // 设置线程名
System.out.println( "The running thread:" + Thread1 );
Thread Thread2 = new Thread( this,"the second thread" );
System.out.println( "creat second thread" );
Thread2.start(); // 启动线程2
Thread Thread3 = new Thread( this,"the third thread" );
System.out.println( "creat third thread" );
Thread3.start(); // 启动线程3
}
public void run() { // 重构run方法
try {
for ( int i = 0; i < 5; i++ ) {
System.out.println( "Sleep time for thread :" + i );
Thread.sleep( 1000 ); // 线程休眠
}
}
catch ( InterruptedException e ) {
System.out.println( "thread has wrong" );
}
}
public static void main(String args[]) {
new ThreeThread(); // 创建3个线程对象
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -