File tree 2 files changed +9
-2
lines changed
src/main/java/com/iluwatar/twin
2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -90,14 +90,17 @@ public class BallThread extends Thread {
90
90
public void run () {
91
91
synchronized (this ) {
92
92
while (isRunning) {
93
- while (isSuspended) {
93
+ while (isSuspended && isRunning ) {
94
94
try {
95
95
wait();
96
96
} catch (InterruptedException e) {
97
97
Thread . currentThread(). interrupt();
98
98
return ;
99
99
}
100
100
}
101
+
102
+ if (! isRunning) break ;
103
+
101
104
twin. draw();
102
105
twin. move();
103
106
try {
Original file line number Diff line number Diff line change @@ -50,14 +50,18 @@ public class BallThread extends Thread {
50
50
public void run () {
51
51
synchronized (this ) {
52
52
while (isRunning ) {
53
- while (isSuspended ) {
53
+ while (isSuspended && isRunning ) {
54
54
try {
55
55
wait (); // Puts the thread in waiting state.
56
56
} catch (InterruptedException e ) {
57
57
Thread .currentThread ().interrupt (); // Restores the interruption.
58
58
return ;
59
59
}
60
60
}
61
+
62
+ if (!isRunning )
63
+ break ; // Secures clean exit
64
+
61
65
twin .draw ();
62
66
twin .move ();
63
67
try {
You can’t perform that action at this time.
0 commit comments