1
votes

I want to pause the "timer" thread....or i can say want to put it into "wait" mode and then notify after something gets completed.

Timer _catchTimer = new Timer(); CatchAppNameTimer _catchTimerTask = new CatchAppNameTimer(_catchTimer); _catchTimer.schedule(_catchTimerTask, 0, 5000);

My "TimerTask ( _catchTimerTask ) " everytime shows a Popup screen ....that popup screen has two buttons - Unlock, Cancel.

basically i want that until user clicks on.... one of the Unlock / cancel btn, Time thread gets set on wait mode..... when user click one of the Unlock / Cancel button............ only after then Time thread gets notifiy.

Currently I am using a boolean variable in run method of "timertask" ..... to handle the deadlock situation...... that is TimerTask get called in every few secs......even when popup screen already shown..........

As follows :

public void run() { 


GlobalSingleton obj = null; 
  obj = GlobalSingleton.getInstance(); 
  if( obj.getShowDialog() ) 
        return;

   unlockField();
}

when first time "unlockFiled()" called........i set a boolean variable as true (using Runtime Store) ....... which value is retrived by getShowDialog() method. and in

fieldChanged(Field field, int context) { } method of both Unlock / Cancel button......... i set the boolean var's value as false...... by calling ...

GlobalSingleton obj = null; obj = GlobalSingleton.getInstance(); obj.setShowDialog(false);

But the right approch is "timer-task" should not be started again....... untilll user press either Unblock / Cancel button and control gets out of the fieldChanged(Field field, int context) { } method.

shuld i use a differnet thread to handle the....wait - notify operations on the Timer object....on the basis of a boolean variable. i hv already tried this approach.......... but cant get a solution...

i'll be gratefull for any suggestions....

Regards.

3

3 Answers

0
votes

As I undestood you have thread that is listen for some evenst and execute this events. Mayby producer-consumer pattern will help:

1 You have producer that put messages to queue

2 You have BlockingQueue where your messages are stored

3 You have thread that read messages from BlockingQueue (if queue is empty thread is wait for message) and depends on message it show/hide your dialog.

Think this will be simplest and clear implementation.

0
votes

Monitor you TimerTask with another Thread.And specify your condition some sort of while loop when it satisfy just notify your Timetask to stop the Job.

0
votes

thanks BOSS and Alexey for ur contribution, I have solved my problem with a continuously running thread having sleep for 1 sec.

My solution is given on - solution or at : main thread Please vote if u find my solution helpful as I need some reputations for start chat on blackberry rooms.

thnks.