⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadrace.java

📁 java的一系列产品中包括jsme,jmse,j2ee,本文件提供j2ee实现的源代码.
💻 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 + -