Advertisement
Josif_tepe

Untitled

Mar 26th, 2022
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) throws InterruptedException{
  3.         Fabrika fabrika = new Fabrika(5);
  4.         Thread[] niza = new Thread[10];
  5.         for(int i = 0; i < 10; i++) {
  6.             niza[i] = new Thread(new Runnable() {
  7.                 @Override
  8.                 public void run() {
  9.                     try {
  10.  
  11.                         fabrika.produce("V");
  12.                     }
  13.                     catch (InterruptedException e) {
  14.                         e.printStackTrace();
  15.                     }
  16.                 }
  17.             });
  18.         }
  19.         Thread[] niza2 = new Thread[10];
  20.         for(int i = 0; i < 10; i++) {
  21.             niza2[i] = new Thread(new Runnable() {
  22.                 @Override
  23.                 public void run() {
  24.                     try {
  25.                         fabrika.consume();
  26.                     }
  27.                     catch (InterruptedException e) {
  28.                         e.printStackTrace();
  29.                     }
  30.                 }
  31.             });
  32.  
  33.         }
  34.         for(int i = 0; i < 10 ; i++) {
  35.             niza[i].start();
  36.             niza[i].join();
  37.             niza2[i].start();
  38.             niza2[i].join();
  39.         }
  40.  
  41.  
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement