Guest User

Untitled

a guest
Jan 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. package mixing;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.List;
  6. import java.util.Random;
  7.  
  8. public class ExampleScenario {
  9.  
  10. class Consumer {
  11.  
  12. private List<Long> timeSlots = new ArrayList<>();
  13.  
  14. public void beginRunning() {
  15. try {
  16. while (true) {
  17. long timeSlot = new Date().getTime() + new Random().nextInt(1000);
  18.  
  19. if (this.timeSlotAvailable(timeSlot)) {
  20. timeSlots.add(timeSlot);
  21. }
  22.  
  23. Thread.sleep(1000);
  24. }
  25. } catch(InterruptedException v) {
  26. System.out.println(v);
  27. }
  28. }
  29.  
  30. public boolean timeSlotAvailable(long startTime) {
  31. return true;
  32. }
  33.  
  34. }
  35.  
  36. public static void main(String[] args) {
  37. ExampleScenario esm = new ExampleScenario();
  38.  
  39. int amountColleagues = 2;
  40.  
  41. Consumer[] colleagues = new Consumer[amountColleagues];
  42.  
  43. for (int i = 0; i < amountColleagues; i++) {
  44. colleagues[i] = esm.new Consumer();
  45. }
  46.  
  47. for (Consumer colleague : colleagues) {
  48. colleague.beginRunning();
  49. }
  50. }
  51.  
  52. }
Add Comment
Please, Sign In to add comment