Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class CThread extends Thread
- {
- Type type;
- Direction dir;
- Manager m;
- public CThread(Manager m)
- {
- this.m = m;
- Random rand = new Random();
- int type = rand.nextInt(2);
- if(type == 0)
- {
- this.type = Type.SLIM;
- }
- else
- {
- this.type = Type.FAT;
- }
- int direction = rand.nextInt(2);
- if(direction == 0)
- {
- this.dir = Direction.NORTH;
- }
- else
- {
- this.dir = Direction.SOUTH;
- }
- }
- public void run()
- {
- m.Acquire(this);
- m.Simulate(2000);
- m.Release(this);
- }
- public static void main(String[] args) throws InterruptedException
- {
- Manager m = new Manager();
- CThread[] vehicles = new CThread[30];
- for(int i = 0 ; i < 30; i++)
- {
- vehicles[i] = new CThread(m);
- vehicles[i].start();
- }
- for(int i = 0 ; i < 30; i++)
- {
- vehicles[i].join();
- }
- }
- }
Add Comment
Please, Sign In to add comment