Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
New Developer
Posts: 43
Registered: ‎08-23-2008
My Device: Not Specified

Timer Class reschedule

Hi
I have a timer class which run on based on the time i schedule but, i need to reschedule time 
 
For example, 
 
 Timer myTimer;
 myTask  = new myTimerFunc();                
 myTimer= new Timer() ;
 myTimer.schedule(myTask, Date and time  here);   
 
 This is ok 
But i want to cancle the this running timer  and change the Date and time in myTimer.schedule to other new Date & time 
 
 
When i do this it is giving me exxception IlliglestateException
 
Appriciate if any help on this with example code... 
Developer
Posts: 213
Registered: ‎07-18-2008
My Device: Not Specified

Re: Timer Class reschedule

[ Edited ]

Looked at the Timer API and this is what it says and mostly the cause of your error message:

 

If the timer's task execution thread terminates unexpectedly, for example, because its stop method is invoked, any further attempt to schedule a task on the timer will result in an IllegalStateException, as if the timer's cancel method had been invoked. 

 

A simple demo code i found on Internet:

 

import java.util.Timer;
import java.util.TimerTask;

/**
* Simple demo that uses java.util.Timer to schedule a task
* to execute once 5 seconds have passed.
*/

public class Reminder {
Timer timer;

public Reminder(int seconds) {
timer = new Timer();
timer.schedule(new RemindTask(), seconds*1000);
}

class RemindTask extends TimerTask {
public void run() {
System.out.format("Time's up!%n");
timer.cancel(); //Terminate the timer thread
}
}

public static void main(String args[]) {
new Reminder(5);
System.out.format("Task scheduled.%n");
}

 

greetings,

 

yosoh


 

Message Edited by yosoh on 10-21-2008 03:41 PM
--------------------------------------------------
problemSolved() ? kudosPlease():kudosPlease();
New Developer
Posts: 43
Registered: ‎08-23-2008
My Device: Not Specified

Re: Timer Class reschedule

yes I came to know about that but how to reschedule?
Developer
Posts: 213
Registered: ‎07-18-2008
My Device: Not Specified

Re: Timer Class reschedule

There is no method to reschedule the timer. Only way is to cancel and schedule it again. Following thread has reply to your questions:

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=4022&query.id=288...

 

greetings,

 

yosoh.

--------------------------------------------------
problemSolved() ? kudosPlease():kudosPlease();
Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: Timer Class reschedule

is it possible to schedule timer to display image for a period of time say 5seconds as soon as an application starts..


Contributor
Posts: 16
Registered: ‎03-01-2011
My Device: 9700
My Carrier: Airtel

Re: Timer Class reschedule

Yes you can do it. Please search for displaying a  splash screen. 

Regards,
KatharNavaS.