Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import java.util.Scanner;
- import java.util.concurrent.Semaphore;
- public class Main {
- public static void main(String[] args) throws InterruptedException{
- Factory f = new Factory(2);
- List<Thread> ls = new ArrayList<>();
- for(int i = 0; i < 3; i++) {
- ls.add(new Thread(new Runnable() {
- @Override
- public void run() {
- Random rnd = new Random();
- if(rnd.nextInt() % 2 == 0) {
- try {
- f.produce_vaccine(new String("v" + rnd.nextInt() % 10));
- }
- catch (InterruptedException ex) {
- }
- }
- else {
- try {
- f.buy_vaccine();
- }
- catch (InterruptedException ex) {
- }
- }
- }
- }));
- }
- for(int i = 0; i < 3; i++) {
- ls.get(i).start();
- }
- for(int i =0; i < 3; i++) {
- try {
- ls.get(i).join();
- }
- catch (InterruptedException ex) {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement