Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Ćwiczenie4;
- import java.util.Scanner;
- public class Main {
- public static boolean endWork = false;
- public static Thread T1;
- private static Object threadArray[];
- private static String password;
- private static Integer threadsNumber;
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Podaj hasło: ");
- password = new StringBuilder().append(scanner.nextLine()).toString();
- System.out.println("Podaj ilość konsumentów: ");
- String M = scanner.nextLine();
- scanner.nextLine();
- threadsNumber = Integer.parseInt(M);
- T1 = new Thread(new Producent());
- T1.start();
- threadArray = new Object[threadsNumber];
- for (int i = 0; i < threadsNumber; i++) {
- Konsument k = new Konsument();
- Thread t = new Thread(k);
- threadArray[i] = t;
- t.start();
- k.threadID = (int) t.getId();
- }
- scanner.close();
- }
- public static void stopThreads() {
- endWork = true;
- }
- public static synchronized String getPassword() {
- return Main.password;
- }
- public static synchronized void closeAllThreads() {
- for (int i = 0; i < threadsNumber; i++) {
- ((Thread) threadArray[i]).interrupt();
- }
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement