Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mixing;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Random;
- public class ExampleScenario {
- class Consumer {
- private List<Long> timeSlots = new ArrayList<>();
- public void beginRunning() {
- try {
- while (true) {
- long timeSlot = new Date().getTime() + new Random().nextInt(1000);
- if (this.timeSlotAvailable(timeSlot)) {
- timeSlots.add(timeSlot);
- }
- Thread.sleep(1000);
- }
- } catch(InterruptedException v) {
- System.out.println(v);
- }
- }
- public boolean timeSlotAvailable(long startTime) {
- return true;
- }
- }
- public static void main(String[] args) {
- ExampleScenario esm = new ExampleScenario();
- int amountColleagues = 2;
- Consumer[] colleagues = new Consumer[amountColleagues];
- for (int i = 0; i < amountColleagues; i++) {
- colleagues[i] = esm.new Consumer();
- }
- for (Consumer colleague : colleagues) {
- colleague.beginRunning();
- }
- }
- }
Add Comment
Please, Sign In to add comment