-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCriminal.java
49 lines (41 loc) · 1.09 KB
/
Criminal.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ThreadlivelockExample;
/**
* @author Virendra Singh
*
* The Class Criminal.
*/
public class Criminal {
/** The hostage relased. */
private boolean hostageRelased;
/**
* Sets the hostage relased.
*
* @param hostageRelased the new hostage relased
*/
public void setHostageRelased(boolean hostageRelased) {
this.hostageRelased = hostageRelased;
}
/**
* Checks if is hostage relased.
*
* @return true, if is hostage relased
*/
public boolean isHostageRelased() {
return this.hostageRelased;
}
/**
* Release hostage.
*
* @param police the police
* @throws InterruptedException the interrupted exception
*/
public void releaseHostage(Police police) throws InterruptedException {
while (!police.isMoneySet()) {
System.out.println(" Police has not given money yet.. We will ask again after 2 seconds");
Thread.sleep(2000);
}
System.out.println(" Wow ..Police has given money , now we can relase hostages");
this.hostageRelased = true;
System.out.println(" Criminals have released hostages");
}
}