我需要帮助来解决这个问题我需要对每个我不知道如何在阵列线程中实现它的人进行随机延迟。请有人帮助我!
我可能需要线程中的链表中的某些内容或其他内容,我需要知道在哪里以及如何实现。我被这个困住了。我想制作一个排列的线程来为每个人做一个延迟
import java.util.concurrent.*;
import java.util.Random;
import java.util.LinkedList;
import java.util.Queue;
public class Try5 extends Thread {
public static Semaphore Door = new Semaphore(3);
public static int COUNTER = 0;
public static final int LIST = 3;
public static int VACANCY = LIST;
//private DELAY_GENERATOR[] Person;
//private LinkedList<Runnable> taskQueue;
public static void main (String[] args) {
class CONTROLLER extends Thread{
int ID;
int SEX;
public CONTROLLER(int a, int b){
ID = a;
SEX = b;
}
public void run(){
while(VACANCY < 0){
if(SEX == 0){
try{
Door.acquire();
VACANCY--;
this.MEN();
System.out.println("MEN has ENTERED The CR");
}catch (InterruptedException ex){}
}
else{
try{
Door.acquire();
VACANCY--;
this.WOMEN();
System.out.println("WOMEN has ENTERED The CR");
}catch (InterruptedException ex){}
}}}
public void MEN(){
System.out.println("MEN has USED The CR");
//taskQueue = new LinkedList<Runnable>();
//Person = new DELAY_GENERATOR[COUNTER];
//Person[COUNTER] = new DELAY_GENERATOR();
//Person[COUNTER].start();
//Queue<Integer> MenQueue = new LinkedList<Integer>();
//MenQueue.offer(COUNTER);
VACANCY++;
Door.release();
}
public void WOMEN(){
System.out.println("WOMEN has USED The CR");
//taskQueue = new LinkedList<Runnable>();
//Person = new DELAY_GENERATOR[COUNTER];
//Person[COUNTER] = new DELAY_GENERATOR();
//Person[COUNTER].start();
//Queue<Integer> WomenQueue = new LinkedList<Integer>();
//WomenQueue.offer(COUNTER);
VACANCY++;
Door.release();
}
}
class DELAY_GENERATOR extends Thread{
public void run(){
try {
Thread.sleep((int)Math.random()*(5000-1000));
} catch (InterruptedException e){
}
}
}
}
}