📄 threadrace.java
字号:
//import goodFrame;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.applet.Applet;
import myThread;
public class ThreadRace extends Applet implements Runnable{
myThread theRacers[];
static int racerCount=3;
Thread theThreads[],thisThread;
int numberofThreadsAtStart;
public void init(){
numberofThreadsAtStart=Thread.activeCount();
setLayout(new GridLayout(racerCount,1));
theRacers=new myThread[racerCount];
theThreads=new Thread[racerCount];
for(int x=0;x<racerCount;x++){
theRacers[x]=new myThread("Racer +"+x);
theRacers[x].resize(size().width,size().height/racerCount);
add(theRacers[x]);
theThreads[x]=new Thread(theRacers[x]);
theThreads[x].setPriority(Thread.MIN_PRIORITY+x*3);
}
}
public void start(){
for(int x=0;x<racerCount;x++)
theThreads[x].start();
thisThread=new Thread(this);
thisThread.start();
}
public void stop(){
thisThread.stop();
}
public void run(){
while(Thread.activeCount()>numberofThreadsAtStart+2){
try{
thisThread.sleep(10);
}catch(InterruptedException e){
System.out.println("thisThread was interrupted");
}
}
stop();
destroy();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -