Here's my code:
public void test(){
final Timer timer = new Timer();
MyThread task;
boolean EXIT = false;
while(!EXIT) {
.............
switch (choice){
case 1:
.............
break;
case 2:
if (loggedUser != null){
MyThread task = new MyThread(loggedUser,library);
timer.schedule(task,0,2000);
while(!logOut) {
menu2.displayMenu();
int choice2 = input.readInteger("",1,9);
switch(choice2){
case 1:
.........................
break;
case 2:
............................
break;
case 3:
break;
case 4:
.............................
break;
case 5:
.............................
break;
case 6:
..............................
break;
case 7:
...............................
break;
case 8:
task.cancel();
timer.purge();
logOut = true;
break;
case 9:
task.cancel();
timer.purge();
logOut = true;
EXIT = true;
break;
}
}
}
break;
case 3:
EXIT = true;
break;
}
}
The problem is that when EXIT option is chosen, the program doesn't end. It looks like the thread is still running, even though the task is not being carried out. What should I change? The thread has to start in the loop as some conditions must be satisfied first. The program ends with no problem when I comment out the thread part.