Hi I dont need more then one thread, or a timer job i would say, this timer should sleep and then activate like after 10 minutes, check the database, if there is nothing to do go back to sleep. I will look into quartz, is it ok to use Java Timer and TimerTask to do it. For example this will be my taslk class MyTimerTask extends TimerTask { public void run() { //Class to check for database } }
Timer tt = new Timer(); tt.scheduleAtFixedRate(myTimerTask, 100000, 100000); In ServletContext i will save instance of myTimerTask and then provide a jsp to stop or start this Task I will make sure that the class with does check database function will not go in loop or be there for ever Any suggestions On 11/5/07, Frank W. Zammetti <[EMAIL PROTECTED]> wrote: > > On Mon, November 5, 2007 10:40 am, Ashish Kulkarni wrote: > > Hi > > I have to write a thread in web application which will check some values > > in > > database, and then perform some function depending on the values. > > > > There wont be any user input and this thread should be called after like > > 10 > > minutes, also i want to have a jsp page from where i can maintain this > > thread, like stop, change the time it should run etc. > > > > Are there any specific J2EE api i can use, or should i just use a time > > thread, and store the handle to this thread in servlet context so i can > > access and modify it.. > > Spawning threads in a servlet container is generally considered Bad > Voodoo(tm). If memory serves, it's even outlawed by the servlet spec. > > That being said, we've all done it, we'll all probably do it again, so > mheh with the recommendations :) > > *That* being said, the key thing is to be extra careful doing it. Make > sure the thread code is as bullet-proof as possible, most especially when > it comes to resource usage. The reason spawning such threads is a bad > idea in the first place is because they are not under control of the > container and cannot be managed, nor can the resources it uses. > Therefore, you'll need to do that yourself and be sure you play nice > within the container. > > Also, be sure to mark it a daemon thread, otherwise you'll find it can and > will hold up shutdown of the container. Bumping its priority as low as > possible is probably also a good idea. > > Or you can do as Chris said and use Quartz, which will deal with most of > these concerns for you. I say most because you can still write bad Quartz > jobs that bork things as badly as if you didn't use Quartz at all, but > it'll help a little bit. > > > Ashish > > Frank > > -- > Frank W. Zammetti > Founder and Chief Software Architect > Omnytex Technologies > http://www.omnytex.com > AIM/Yahoo: fzammetti > MSN: [EMAIL PROTECTED] > Author of "Practical Ajax Projects With Java Technology" > (2006, Apress, ISBN 1-59059-695-1) > and "JavaScript, DOM Scripting and Ajax Projects" > (2007, Apress, ISBN 1-59059-816-4) > Java Web Parts - http://javawebparts.sourceforge.net > Supplying the wheel, so you don't have to reinvent it! > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >