📄 chap9-5.txt
字号:
// 程序9-5
class UserThread{
void Play(int n) {
System.out.println("运行线程 NO:"+n);
try{
Thread.sleep(3); // 采用睡眠模拟程序的运行
}catch(InterruptedException e) {
System.out.println("线程异常,NO:"+n);
}
System.out.println("结束线程 NO:"+n);
}
}
class UserMultThread implements Runnable{
UserThread UserObj;
int num;
UserMultThread(UserThread o,int n) {
UserObj=o;
num=n;
}
public void run( ) {
UserObj.Play(num);
}
}
public class multTheadTwo {
public static void main(String args[ ]) {
UserThread Obj=new UserThread( ); // 定义对象Obj
Thread t1=new Thread(new UserMultThread(Obj,1)); // 采用Obj产生线程对象
Thread t2=new Thread(new UserMultThread(Obj,2));
Thread t3=new Thread(new UserMultThread(Obj,3));
t1.start( );
t2.start( );
t3.start( );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -