Hi.
You can do something as follows, I did not compile or run the code.
Hope it helps.
Thanks
Neelesh
/** ITimedObject.java /
Interface ITimedObject(){
void onTimer();
}
/** Timer.java */
// calls the ITimedObject method after a certain
// amount of time has elapsed.
// note this thread runs for ever, you will have to device some
// way to kill it, you may use the ITimedObject interface again to
// do this if you wish.
class Timer implements Runnable{
private ITimedObject owner;
private Date interval;
private boolean stayAlive;
private int sleepTime;
public Timer(ITimedObject timedObj, Date recurringInterval){
this.owner=timeObj;
this.inteval = recurringInterval;
this.stayAlive = true;
//hard coded wake up time, you can be smart about
configuring this.
this.sleepTime = 120000;
}
public void run(){
Calender c = Calendar.getInstance();
Calender timeDiffCal = (Calender)c.clone();
//note works only if the even recurs each day.
timeDiffCal.setTime(Calender.DAY, this.interval);
Date now = c.getTime();
Date timeDiff = timeDiffCal.getTime();
while(stayAlive){
now = c.getTime();
if(now.after(timeDiff)){
owner.onTimer();
}else{
try{
Thread.sleep(this.sleepTime);
}catch(InterruptedException ie){
}
}
}
}
}
/** Scheduler.java */
class Scheduler implements ITimedObject{
private Date interval;
private Timer eventTimer;
public Scheduler(Date eventRecurringInterval){
this.interval= recurringInterval;
this.eventTimer = new Timer(this);
}
void run(){
eventTimer.start();
}
void onTimer(){
// do the tasks that are scheduled every
// "interval" days.
}
}
-----Original Message-----
From: Tom John [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 14, 1999 12:00 AM
To: [EMAIL PROTECTED]
Subject: Re: THREAD PROBLEM!!!!!!!!!
Hi,
Thanks Ted, I tried it was not successful,Infact am a student doing my final
year project, If You can send me the relevant code for the ScheduledThread(
A thread that periodically checks the current time,if satisfied do some
operations
as appropiate)
that would be fine,
Thanks
TOM
At 10:14 PM 12/13/99 -0800, you wrote:
>Create a "ScheduledThread" that periodically checks the current time, and
>doesn't execute the Runnable's run() method until it's past the given
>criteria. Then fire the ScheduledThread off like so:
>
>java.util.Date = get_date_for_later(); // whenever that's supposed to be
>new ScheduledThread(new Runnable() {
> public void run()
> {
> }
> }).start();
>
>and forget about it until it's completed.
>
><SHAMELESS PLUG>
>I describe how to do precisely this in my forthcoming book, "Server-Side
>Java" ( http://www.manning.com/Neward3 ).
></SHAMELESS PLUG>
>
>If you can't get it to work, I'll fire the code I came up with to you.
>
>Ted Neward
>http://www.javageeks.com/~tneward
>
>
>On Tue, 14 Dec 1999, Tom John wrote:
>
>> Hi,
>>
>> I wan't to write a THREAD in my project(client/server web based
project)
>> What I need is, to execute a servlet on a particular day which has been
>> given earlier(the day).
>> Early response highly appreciated
>>
>> TOM
>>
>>
___________________________________________________________________________
>> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
>> of the message "signoff SERVLET-INTEREST".
>>
>> Archives: http://archives.java.sun.com/archives/servlet-interest.html
>> Resources: http://java.sun.com/products/servlet/external-resources.html
>> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>>
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html