It's not a secret anymore!
The moose likes Servlets and the fly likes load-on-startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "load-on-startup" Watch "load-on-startup" New topic


James Clarke
Ranch Hand

Joined: Oct 04, 2004
Posts: 148
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. ?


Jaime M. Tovar
Ranch Hand

Joined: Mar 28, 2005
Posts: 133
Never tried it but let me ask why you are doing that???

She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

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.

[Asking smart questions] [About Bear] [Books by Bear]
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

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.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

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:

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: load-on-startup
It's not a secret anymore!