I stand corrected.
You are right, of course. The only snag is that when a new event is added that times
out before the one currently waited for, you will have to pull the thread out of it's
waiting and then send it to sleep again with a new timeout. A little extra logic is
needed, but it's a lot more CPU-efficient.
Michael
-----Oprindelig meddelelse-----
Fra: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]På vegne af Kevin
Mukhar
Sendt: Thursday, September 07, 2000 4:09 PM
Til: [EMAIL PROTECTED]
Emne: Re: SV: Threads and Servlets
MBP wrote:
>
> I can't know what you're trying to implement, but in general a better
> solution would involve a list of events and a scheduler. The servlet would
> add an event to the list and then forget about it. The scheduler would scan
> the list every X seconds and handle any timed-out events.
> An added bonus is that you can restart your server without losing events.
The event list and scheduler are good ideas. Scanning the list every X
seconds is not very good. Better would be to put the scheduler into a
wait for the number of seconds until the next event. Notify the
scheduler when a new event is added so that it can add the new event and
adjust its wait time.
___________________________________________________________________________
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