📄 chap9-4.txt
字号:
// 程序9-4
class threadTest extends Thread{// 定义一个thread的子类
threadTest(String str){
super(str); // 调用父类构造函数设置线程的名字
}
public void run( ){
try{
Thread.sleep(2); // 睡眠2毫秒,通过睡眠模拟程序的执行
}catch(InterruptedException e) {
System.err.println(e.toString( ));
}
System.out.println(getName( )+" " +getPriority( )); // 输出线程的名字和优先级
}
}
public class multTheadOne{ // 定义一个主类
public static void main(String agrs[]){
Thread one=new threadTest("one" ); // 定义3个线程对象
Thread two=new threadTest("two" );
Thread three=new threadTest("three" );
one.setPriority(Thread.MIN_PRIORITY); // 设置各个线程的优先级
two.setPriority(Thread.NORM_PRIORITY);
three.setPriority(Thread.MAX_PRIORITY);
one.start( ); // 首先启动one线程
two.start( );
three.start( );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -