-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lecture: amend challenges for Multi-Threading lesson
- Loading branch information
Showing
6 changed files
with
52 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
package threads; | ||
|
||
public record BlueHamster(String name, Tunnel tunnel) implements Hamster {} | ||
import java.util.stream.IntStream; | ||
|
||
public record BlueHamster(String name, Tunnel tunnel) implements Hamster { | ||
|
||
public void idle() { | ||
IntStream.range(0, 5).forEach(i -> System.out.println(name() + ": (blue) wandering idly")); | ||
} | ||
|
||
public void moveThroughTunnel() { | ||
System.out.println(name() + ": => (blue) entering tunnel"); | ||
tunnel().enter(this); | ||
System.out.println(name() + ": => (blue) entered tunnel"); | ||
|
||
IntStream.range(0, 2) | ||
.forEach(i -> System.out.println(name() + ": (blue) moving through tunnel")); | ||
|
||
System.out.println(name() + ": (blue) leaving tunnel =>"); | ||
tunnel().leave(this); | ||
System.out.println(name() + ": (blue) left tunnel =>"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
package threads; | ||
|
||
public record RedHamster(String name, Tunnel tunnel) implements Hamster {} | ||
import java.util.stream.IntStream; | ||
|
||
public record RedHamster(String name, Tunnel tunnel) implements Hamster { | ||
|
||
public void idle() { | ||
IntStream.range(0, 5).forEach(i -> System.out.println(name() + ": (red) wandering idly")); | ||
} | ||
|
||
public void moveThroughTunnel() { | ||
System.out.println(name() + ": => (red) entering tunnel"); | ||
tunnel().enter(this); | ||
System.out.println(name() + ": => (red) entered tunnel"); | ||
|
||
IntStream.range(0, 2) | ||
.forEach(i -> System.out.println(name() + ": (red) moving through tunnel")); | ||
|
||
System.out.println(name() + ": (red) leaving tunnel =>"); | ||
tunnel().leave(this); | ||
System.out.println(name() + ": (red) left tunnel =>"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters