It is really strange and I don't know what to think here.
I have a little timer program that creates a thread with certain operations. One of these operations is creating one more thread to do the actual count down.
The problem is that it doesn't work as expected when I simply run the program (timer freezes at 05:00). However, when I try to do things in debug mode and set breakpoints in the suspicious lines the execution passes through! And it counts down below 5 minutes as expected, but with a little warning message:
I/PomoACt﹕ 04 : 56
I/Choreographer﹕ Skipped 57 frames! The application may be doing too much work on its main
I/PomoACt﹕ 04 : 55
I/Choreographer﹕ Skipped 58 frames! The application may be doing too much work on its main thread.
Well the message from choreographer is probably due to slowness of emulator, but why is there a difference in the execution flow of regular vs debug mode?
EDIT: Posting code as requested.
This is a thread which instance I run inside of the main UI thread:
@Override
public void run() {
pomodoroLeft = numPomodoro;
while(pomodoroLeft > 0) {
pomodoroLeft--;
runTime = TWENTY_MINUTES; //runTime is needed for timerUpdate
timerUpdate(); //This method just updates
//textWiew with the current value of
//runTime
runnable = new Clock();
timerRun = true;
runnable.run();
waitForClock();
Log.i("while", "execution in while");
runTime = FIVE_MINUTES;
Log.i("while", "execution in while 2");
runnable = new Clock();
timerRuns = true;
Log.i("while", "execution in while 3");
timerUpdate();
runnable.run(); //This is form where the execution
//misbehaves
waitForClock();
public class Clock implements Runnable
{
public void run() {
if (!timerRuns) {
return;
}
Log.i("PomoACt", timeShown.getText().toString()); //To log currently
//displayed value
runTime -= ONE_SECOND;
timerUpdate();
mHandler.postDelayed(this, 1000); //Wait a second
if(timeShown.getText().toString().contentEquals("00 : 00")) {
stopClock();
synchronized (runnable) {
runnable.notify(); //Notify the waiting
//thread that it should
//go on with execution
Log.i("Not", "notified from runnabe");
}
//here goes the alarm.
}
}
}
public void stopClock() {
timerRuns = false;
mHandler.removeCallbacks(runnable);
}
public void waitForClock() {
synchronized(runnable){
try{
runnable.wait(); //Wait for the current runnable to
//compliete
} catch(InterruptedException e){}
}
}
And so TWENTY_MINUTES loop gets executed as expected, but FIVE_MINUTE loop doesn't. It only executes ones, thus showing 4:59 on emulator. It executes fine during debugging session.