Advertisement
lashrone1

rooms

Oct 24th, 2019
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1.  
  2.  
  3. public class Main {
  4.  
  5. static int DELAY = 100;
  6. static int LIVING_DELAY = 40;
  7. static int PEOPLE_AMOUNT = 10;
  8.  
  9. public static int ThPause = 0;
  10. public static int rooms_amount = 3;
  11. public static boolean [] room_status = new boolean[rooms_amount];
  12.  
  13.  
  14. public static synchronized void checkIn(int client) {
  15.  
  16. for (int i = 0; i < room_status.length; i++) {
  17. if(room_status[i]){
  18. ThPause=1;
  19. continue;
  20. }
  21. room_status[i]=true;
  22. System.out.println("Клиент "+client+" занял номер " + i);
  23.  
  24. break;
  25. }
  26.  
  27. }
  28.  
  29.  
  30. public static synchronized void checkOut(int client){
  31.  
  32. }
  33.  
  34. public static void main (String[] args) {
  35.  
  36. for(int i = 0;i<rooms_amount;i++){
  37. room_status[i] = false;
  38. }
  39.  
  40.  
  41.  
  42. for(int i=0; i<PEOPLE_AMOUNT; i++){
  43. int tmp=i;
  44. Runnable r = new Runnable() {
  45.  
  46. @Override
  47. public void run() {
  48.  
  49.  
  50.  
  51. if (ThPause==1) {
  52.  
  53. try {
  54. synchronized (this) {
  55. this.wait();
  56. }
  57. } catch (InterruptedException var6) {
  58. var6.printStackTrace();
  59. }
  60. }
  61. else {
  62.  
  63.  
  64. checkIn(tmp);
  65.  
  66. try {
  67. Thread.sleep(LIVING_DELAY);
  68. } catch (InterruptedException ex) {}
  69.  
  70.  
  71.  
  72. }
  73.  
  74. try {
  75. Thread.sleep(DELAY);
  76. } catch (InterruptedException ex) {}
  77.  
  78. }
  79. };
  80.  
  81. Thread t = new Thread(r);
  82. t.start();
  83.  
  84. }
  85.  
  86.  
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement