Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- static int DELAY = 100;
- static int LIVING_DELAY = 40;
- static int PEOPLE_AMOUNT = 10;
- public static int ThPause = 0;
- public static int rooms_amount = 3;
- public static boolean [] room_status = new boolean[rooms_amount];
- public static synchronized void checkIn(int client) {
- for (int i = 0; i < room_status.length; i++) {
- if(room_status[i]){
- ThPause=1;
- continue;
- }
- room_status[i]=true;
- System.out.println("Клиент "+client+" занял номер " + i);
- break;
- }
- }
- public static synchronized void checkOut(int client){
- }
- public static void main (String[] args) {
- for(int i = 0;i<rooms_amount;i++){
- room_status[i] = false;
- }
- for(int i=0; i<PEOPLE_AMOUNT; i++){
- int tmp=i;
- Runnable r = new Runnable() {
- @Override
- public void run() {
- if (ThPause==1) {
- try {
- synchronized (this) {
- this.wait();
- }
- } catch (InterruptedException var6) {
- var6.printStackTrace();
- }
- }
- else {
- checkIn(tmp);
- try {
- Thread.sleep(LIVING_DELAY);
- } catch (InterruptedException ex) {}
- }
- try {
- Thread.sleep(DELAY);
- } catch (InterruptedException ex) {}
- }
- };
- Thread t = new Thread(r);
- t.start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement