On 7/1/03 6:03 PM, "Ciramella, EJ" <[EMAIL PROTECTED]> wrote:

> Yeah, but the more and more I ask the more I hear that generating threads is
> a no-no.
> 
> But that's exactly what I was thinking.  I want the class to launch when
> this particular webapp is started and die when the webapp (or tomcat) is
> shut down.  And it should run every five minutes or so.
> 
> I have the functionality of the thread, sleep, loop, jdbc work all hammered
> out in a java application, the question is how do I get this to launch
> during the startup of my webapp.
> 
> What I meant earlier about the methodology is if it would be better to use
> some sort of listener (grey area to me) to await access to a resource and
> then run versus creating a separate thread.
> 
> Thanks for the ideas guys, keep 'em commin'!!!
> 
> -----Original Message-----
> From: Andre D Bonner [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, July 01, 2003 5:55 PM
> To: Tomcat Users List
> Subject: Re: Running a class on startup - java newbie....
> 
> 
>> What I'd like to do is
>> have <something> running that sleeps for 5 minutes at a time and then
> checks
>> to see if 24 hours have passed since the row was inserted (and if so,
> delete
>> it).  Is there a way to start up a class with my web app?
>> 
> 
> 
> Looks like good old Thread based timer
> 
> It is a thread that sits and calls a method every 5 minutes?
> 
> while(true){
> Thread.sleep(5 * 60 * 1000) // 5 minutes exactly
> 
> // lookup my jdbc Datasource
> // do my jdbc checking?
> // releaseConnection
> // loop
> }
> 

Who ever told you that spawning threads is a no-no IS AN IDIOT!!!

Java's Thread model is one of the sole reason's for its use and
proliferation.

Stuff like JSP that all of the other crap people use is thread based.

ALL OF IT!!!!. It is the basis of EVERY SUCCESSFUL J2EE TECHNOLOGY!!!!!




ServletContextListener

 public void contextInitialized(ServletContextEvent event) {

    //        create your thread, setDaemon(true), and place a reference to
//the thread inside as a
        
     getSevletContext(). setAttribute("backgroundThread",backgroundThread);

 }



public void contextDestroyed(ServletContextEvent event) {

    (Thread)getSevletContext().getAttribute("backgroundThread");
  
    Thread.interrupt();

}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to