<OPINION>
Dude, you have *got* to slow down--I've gotten three emails now from you
since last night, and I'm beginning to regret having offered code in the
first place:
"I sent two emails to U but with no reply, am waiting till U send me the
piece of code for a ScheduledThread.
Waiting for Your Early reply"
Emails like this just encourage me not to respond at all, especially when
those two emails were approximately 6 hours apart, one at noon, and one at
6PM, both of which are during my workday--ain't NO way I was going to get
them before I got home.
Remember that offers like this are based on goodwill--show appreciation when
the offer is made, and don't start flooding people with emails when they
haven't responded as quickly as you'd have liked. It's rather sort of like
being given a present, then whining that the giver is taking too long to
give it to you--if you're not careful, they won't give it to you at all.
And for heaven's sake, STOP SHOUTING IN YOUR EMAILS!!!!
</OPINION>
(Sorry folks, just had to get that out of my system first. Hope I didn't
piss too many people off with that. :( )
What Neelesh posted to this list earlier today is a perfectly acceptable
approach, and would work for you in just about every respect; mine is
slightly more compact, but basically looks like so:
package com.javageeks.thread;
public class ScheduledThread extends Thread
{
private java.util.Date m_when;
private Runnable m_runnable;
public ScheduledThread(Runnable runnable, java.util.Date when)
{
m_runnable = runnable;
m_when = when;
}
public void run()
{
try
{
// Make sure "when" is after now.
//
while (m_when.after(new java.util.Date()))
{
Thread.sleep(1000);
}
// If the above test failed, it's time
// to run our target
//
m_runnable.run();
}
catch (InterruptedException intEx)
{
return;
}
}
}
As you can see, it's pretty straightforward--just sleep() every second until
we're past the scheduled date. Usage is pretty straightforward, too:
new ScheduledThread(new Runnable() { public void run() { ... } }, new
ate( ... )).start():
Hope this helps.
Ted Neward
Java Instructor, DevelopMentor ( http://www.develop.com )
http://www.javageeks.com/~tneward
-----Original Message-----
From: Tom John <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Monday, December 13, 1999 11:19 PM
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