File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
src/main/java/com/iluwatar/twin Expand file tree Collapse file tree 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 {
9090 public void run () {
9191 synchronized (this ) {
9292 while (isRunning) {
93- while (isSuspended) {
93+ while (isSuspended && isRunning ) {
9494 try {
9595 wait();
9696 } catch (InterruptedException e) {
9797 Thread . currentThread(). interrupt();
9898 return ;
9999 }
100100 }
101+
102+ if (! isRunning) break ;
103+
101104 twin. draw();
102105 twin. move();
103106 try {
Original file line number Diff line number Diff line change @@ -50,14 +50,18 @@ public class BallThread extends Thread {
5050 public void run () {
5151 synchronized (this ) {
5252 while (isRunning ) {
53- while (isSuspended ) {
53+ while (isSuspended && isRunning ) {
5454 try {
5555 wait (); // Puts the thread in waiting state.
5656 } catch (InterruptedException e ) {
5757 Thread .currentThread ().interrupt (); // Restores the interruption.
5858 return ;
5959 }
6060 }
61+
62+ if (!isRunning )
63+ break ; // Secures clean exit
64+
6165 twin .draw ();
6266 twin .move ();
6367 try {
You can’t perform that action at this time.
0 commit comments