Änderungen 05.12.2023 um 14:44
This commit is contained in:
parent
6f46678393
commit
582ed1a694
@ -10,16 +10,27 @@ public class Fork {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getId(){
|
public int getId(){
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean take(){
|
public boolean take(){
|
||||||
|
synchronized (this){
|
||||||
|
if (inUse){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
inUse = true;
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}catch (InterruptedException e){
|
||||||
|
System.out.println("Gabel mit ID: " + id + " hat nicht funktioniert");
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void put(){
|
public void put(){
|
||||||
|
synchronized(this){
|
||||||
|
inUse = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
7
src/DiningPhilosophers/ForkTest.java
Normal file
7
src/DiningPhilosophers/ForkTest.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package Prog3.src.DiningPhilosophers;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class ForkTest {
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user