import java.util.*; import java.awt.*; import java.awt.event.*; public class MainScheduler extends Thread { //ThreadStatusVariablen private static int pidCounter = 1; public static final int RUN = 0; public static final int RDY = 1; public static final int BLK = 2; public static final int MAXSIZE_STACK = 20; public static int sleeptime = 100; //Producer/Consumer Arrays private static Producer[] prods = new Producer[50]; private static Consumer[] cons = new Consumer[50]; //Stacks und Vectoren der Threads private static Vector readyQueue = new Vector(); public static Stack stack = new Stack(); public static Stack blklist = new Stack(); //Fenster Eigenschaften public static Frame Output = new Frame("Producer/Consumer Programm by Christoph Hocker alias erZ"); public static TextArea output = new TextArea("Willkommen zum P/C-Lottery Programm\n" + "Stack-Start beschreibt die anfängliche Größe \ndes Stacks." + "Sleep-Timer beschreibt die Zeit \nzwischen eine Art Pause zwischen den \nConsumern und Producern.\n" + "Producer/Consumer Aktionen beschrieben die \nstatistische Funktion wie oft produziert bzw \nkonsumiert wurde. " + "Anzahl der Producer/Consumer\nbeschreibt die Anzahl der Threads von Consumern \nund Producern. " + "Bitte achten Sie jeweils auf das\nIntervall. Sollten Fehleingaben getätigtwerden,\nso werden die Standartwerte genutzt\n" + "Mit Start gehts los, mit Stopp ist das Spiel vorbei :-)\n\nBugreport: sichhock@hi-zigr.de\nViel Spaß."); public static Button start = new Button("Start"); public static Button stopp = new Button("Stopp"); public static TextField value = new TextField("10"); public static TextField value2 = new TextField("100"); public static Label text = new Label("Stack-Start:"); public static Label text2 = new Label("(Interval 0 - 20)"); public static Label text3 = new Label("Sleep-Timer:"); public static Label text4 = new Label("(Interval 0 - 10000)"); public static Label ptext = new Label("Producer Aktionen:"); public static Label ptext1 = new Label("0"); public static Label ctext = new Label("Consumer Aktionen:"); public static Label ctext1 = new Label("0"); public static Label textpanz = new Label("Anzahl der Producer:"); public static Label textcanz = new Label("Anzahl der Consumer:"); public static TextField panz = new TextField("5"); public static TextField canz = new TextField("5"); public static Label panzinfo = new Label("(Interval 1 - 50)"); public static Label canzinfo = new Label("(Interval 1 - 50)"); //Statikstik Variablen public static int pAnz = 0; public static int cAnz = 0; public static String showStack() { String result=""; switch(stack.size()) { case 0: result = "[____________________]";break; case 1: result = "[X___________________]";break; case 2: result = "[XX__________________]";break; case 3: result = "[XXX_________________]";break; case 4: result = "[XXXX________________]";break; case 5: result = "[XXXXX_______________]";break; case 6: result = "[XXXXXX______________]";break; case 7: result = "[XXXXXXX_____________]";break; case 8: result = "[XXXXXXXX____________]";break; case 9: result = "[XXXXXXXXX___________]";break; case 10: result = "[XXXXXXXXXX__________]";break; case 11: result = "[XXXXXXXXXXX_________]";break; case 12: result = "[XXXXXXXXXXXX________]";break; case 13: result = "[XXXXXXXXXXXXX_______]";break; case 14: result = "[XXXXXXXXXXXXXX______]";break; case 15: result = "[XXXXXXXXXXXXXXX_____]";break; case 16: result = "[XXXXXXXXXXXXXXXX____]";break; case 17: result = "[XXXXXXXXXXXXXXXXX___]";break; case 18: result = "[XXXXXXXXXXXXXXXXXX__]";break; case 19: result = "[XXXXXXXXXXXXXXXXXXX_]";break; case 20: result = "[XXXXXXXXXXXXXXXXXXXX]";break; } return result; } public static void fillStack(int size) { if (size >= 0 && size <= 20 ) { for(int i=0;i= 0 && timer <= 10000) { sleeptime = timer; } } public static void lottery() { while(true) { int zz = new Random().nextInt(readyQueue.size()); int pidtemp = readyQueue.elementAt(zz).pid; //Algorythmus um keine doppelten Threads aufzurufen if(!blklist.empty()) { //Falls eine Blockliste existiert ist das aufrufen doppelter Threads erst notwendig, damit nicht zwei mal bei einer leeren Liste consumiert wird boolean again = true; while(again) { again = false; for(int i=0;i0 && anz <=50)) anz=5; for(int i=0;i0 && anz <=50)) anz=5; for(int i=0;i