Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

load-on-startup

 
James Clarke
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

If I initiate a servlet inside <load-on-startup> and have an infinite
loop inside the servlet ie. for(; , would this cause major performance
problems in terms of the server, servlet container etc. ?

thanks,

J.C
 
Jaime M. Tovar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never tried it but let me ask why you are doing that???
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry if I sound rude, but the question seems so silly as to almost be a joke. Of course you are going to introduce performance issues if you put elements into infinite loops.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a kind of similar question - posted here a couple of weeks back. Dint get any helpful replies though. Sorry if I sound silly or stupid, but why is it worong to have a infinite loop running somewhere in a web application? In my case, I need to have a thread that polls a log file every, say, 5 seconds. I am not in favour of having a Servlet do this task - would assign it to a ContextListener rather.

Thanks,
Ram.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just putting an endless loop in the init method would keep the init method from returning.

If you want something to run continuously in the background, you would want start a separate thread.
There are APIs specifically designed for this.
Check out java.util.Timer or Quartz.

The following article might be of interest to you:
http://www.onjava.com/pub/a/onjava/2004/03/10/quartz.html?page=1
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic