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;
- public class Main {
- public static void main(String[] args) {
- List<Thread> list = new ArrayList<>();
- final Factory f = new Factory(5);
- int i;
- for(i = 0; i < 5; i++) {
- list.add(new Thread(new Runnable() {
- @Override
- public void run() {
- Random rand = new Random();
- if(rand.nextInt() % 2 == 0) {
- f.buy_vaccine();
- }
- else {
- f.produce_vaccine("v1");
- }
- }
- }));
- }
- for( i = 0; i < 5; i++) {
- list.get(i).start();
- }
- for( i = 0; i < 5; i++) {
- try {
- list.get(i).join();
- }
- catch (InterruptedException ex)
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement