подскажите плз что не так.
Насколько я понимаю нам нужно в методе Взлет выставить значение меньше 100 мс - ок прошло.
чем метод ожидание от него отличается?
или нужно сделать чтобы не сам метод работал меньше 100 мс, а именно самолет ожидал меньше 100 мс?
что-то я запутался:)) распутайте пожалуйста
package com.javarush.task.task16.task1615;
/*
Аэропорт
*/
public class Solution {
public static volatile Runway RUNWAY = new Runway(); //1 взлетная полоса
public static void main(String[] args) throws InterruptedException {
Plane plane1 = new Plane("Самолет #1");
Plane plane2 = new Plane("Самолет #2");
Plane plane3 = new Plane("Самолет #3");
}
private static void waiting() {
//add your code here - добавь код тут
//fix this method - исправь этот метод
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
}
private static void takingOff() {
//fix this method - исправь этот метод
try {
Thread.sleep(98);
} catch (InterruptedException e) {
}
}
public static class Plane extends Thread {
public Plane(String name) {
super(name);
start();
}
public void run() {
boolean isAlreadyTakenOff = false;
while (!isAlreadyTakenOff) {
if (RUNWAY.trySetTakingOffPlane(this)) { //если взлетная полоса свободна, занимаем ее
System.out.println(getName() + " взлетает");
takingOff();//взлетает
System.out.println(getName() + " уже в небе");
isAlreadyTakenOff = true;
RUNWAY.setTakingOffPlane(null);
} else if (!this.equals(RUNWAY.getTakingOffPlane())) { //если взлетная полоса занята самолетом
System.out.println(getName() + " ожидает");
waiting(); //ожидает
}
}
}
}
public static class Runway { //взлетная полоса
private Thread t;
public Thread getTakingOffPlane() {
return t;
}
public void setTakingOffPlane(Thread t) {
synchronized (this) {
this.t = t;
}
}
public boolean trySetTakingOffPlane(Thread t) {
synchronized (this) {
if (this.t == null) {
this.t = t;
return true;
}
return false;
}
}
}
}