Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) throws InterruptedException{
- Fabrika fabrika = new Fabrika(5);
- Thread[] niza = new Thread[5];
- for(int i = 0; i < 5; i++) {
- niza[i] = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- fabrika.produce("V");
- }
- catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- });
- }
- Thread[] niza2 = new Thread[5];
- for(int i = 0; i < 5; i++) {
- niza2[i] = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- fabrika.consume();
- }
- catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- });
- }
- for(int i = 0; i < 5; i++) {
- niza[i].start();
- niza2[i].start();
- niza[i].join();
- niza2[i].join();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement