View Single Post
Old 02-14-2010, 04:50 AM   #9 (permalink)
MobileDeveloperUK
Thumbs Must Hurt
 
Join Date: Jan 2010
Model: 8300
PIN: N/A
Carrier: T-Mobile
Posts: 62
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default

This is the code that I use the timer to execute

Code:


 synchronized (this)
 
 {
                 
 
Timer timer = new Timer();

TimerTask updateTask;
 
 


  
      
updateTask = new TimerTask() {
 
 
 int skppdTms ;
 
   
 public  synchronized void run() {

  System.out.println(" Timer has been invoked " );
 
 if ( skppdTms ==5)
       
       {
   
  skppdTms=0;
          
System.out.println("  skppdTms is 5  :   " );
 
          }
 
  skppdTms=skppdTms+1;
    
    System.out.println(" Skipped Times " + skppdTms);
  
        
}
      

};

timer.scheduleAtFixedRate(updateTask, 2500, 2500);

  }

when I run it I get result like the following

( I exited off the simulator after some time )
Code:
 Timer has been invoked 
 Skipped Times 1
 Timer has been invoked 
 Skipped Times 1
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Skipped Times 1
 Skipped Times 1
 Skipped Times 1
 Skipped Times 1
 Skipped Times 1
 Timer has been invoked 
 Skipped Times 2
 Timer has been invoked 
 Skipped Times 2
 Timer has been invoked 
 Skipped Times 2
 Timer has been invoked 
 Skipped Times 2
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Skipped Times 2
 Skipped Times 2
 Skipped Times 2
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Skipped Times 3
 Skipped Times 3
 Skipped Times 3
 Skipped Times 3
 Skipped Times 3
 Skipped Times 3
 Skipped Times 3
 Timer has been invoked 
 Skipped Times 4
 Timer has been invoked 
 Skipped Times 4
 Timer has been invoked 
 Skipped Times 4
 Timer has been invoked 
 Skipped Times 4
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Skipped Times 4
 Skipped Times 4
 Skipped Times 4
 Timer has been invoked 
 Skipped Times 5
 Timer has been invoked 
 Skipped Times 5
 Timer has been invoked 
 Skipped Times 5
 Timer has been invoked 
 Skipped Times 5
 Timer has been invoked 
 Skipped Times 5
 Timer has been invoked 
 Skipped Times 5
 Timer has been invoked 
 Skipped Times 5
 Timer has been invoked 
  skppdTms is 5  :   
 Skipped Times 1
 Timer has been invoked 
  skppdTms is 5  :   
 Skipped Times 1
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
 Timer has been invoked 
  skppdTms is 5  :   
  skppdTms is 5  :   
  skppdTms is 5  :   
  skppdTms is 5  :   
  skppdTms is 5  :   
 Skipped Times 1
 Skipped Times 1
 Skipped Times 1
 Skipped Times 1
 Skipped Times 1

What I EXPECTED was like this

Code:
Timer has been invoked 
 Skipped Times 1
 Skipped Times 2
 Skipped Times 3
 Skipped Times 4
 Skipped Times 5
skppdTms is 5  :
Timer has been invoked 
 Skipped Times 1
Offline   Reply With Quote