+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

Wei-Lun Hungadd chap. 2 and 3df69975

master
698 B24 linesraw
1class Philosopher implements Runnable {
2    int id = 0;
3    Resource r = null;
4    public Philosopher(int initId, Resource initr) {
5        id = initId;
6        r = initr;
7        new Thread(this).start();
8    }
9    public void run() {
10        while (true) {
11            try {
12                System.out.println("Phil " + id + " thinking");
13                Thread.sleep(30);
14                System.out.println("Phil " + id + " hungry");
15                r.acquire(id);
16                System.out.println("Phil " + id + " eating");
17                Thread.sleep(40);
18                r.release(id);
19            } catch (InterruptedException e) {
20                return;
21            }
22        }
23    }
24}