fix Java8 DiningHakkers sample
This commit is contained in:
parent
33bc502c76
commit
039e8261ff
1 changed files with 6 additions and 8 deletions
|
|
@ -60,6 +60,12 @@ public class DiningHakkersOnBecome {
|
|||
this.name = name;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
|
||||
//All hakkers start in a non-eating state
|
||||
receive(ReceiveBuilder.matchEquals(Think, m -> {
|
||||
System.out.println(String.format("%s starts to think", name));
|
||||
startThinking(Duration.create(5, SECONDS));
|
||||
}).build());
|
||||
}
|
||||
|
||||
//When a hakker is eating, he can decide to start to think,
|
||||
|
|
@ -124,14 +130,6 @@ public class DiningHakkersOnBecome {
|
|||
right.tell(new Take(self()), self());
|
||||
}).build();
|
||||
|
||||
//All hakkers start in a non-eating state
|
||||
public Hakker() {
|
||||
receive(ReceiveBuilder.matchEquals(Think, m -> {
|
||||
System.out.println(String.format("%s starts to think", name));
|
||||
startThinking(Duration.create(5, SECONDS));
|
||||
}).build());
|
||||
}
|
||||
|
||||
private void startThinking(FiniteDuration duration) {
|
||||
context().become(thinking);
|
||||
context().system().scheduler().scheduleOnce(duration, self(), Eat, context().system().dispatcher(), self());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue