File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes A couple of init() questions... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "A couple of init() questions..." Watch "A couple of init() questions..." New topic

A couple of init() questions...

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401

In my init() method, I want a loop that loops forever ( while(true){... ). Can I do this in the init() method? Do I just do it in a new thread?

Also, what is the purpose of the super.init(config) line? What happens if I leave it in? What happens if I leave it out?

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Something like that should be in another thread. Kicked off in a context listener. You should also make sure you have a solid way of killing this thread from the contextDestroyed method of your listener or make sure you are using daemon threads. Otherwise, you may have trouble reloading your app and/or stopping and restarting you server.

I generally advise against starting your own threads in a webapp unless, you really know what you're doing and can't find any alternative.

Mind sharing what you are using the loop for?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Hiya Ben,

Thanks for the reply.

It's to constantly re-read a dynamic web page, from which the servlet is taking the required bits to create a new web page.

I agree. Here's the link:
subject: A couple of init() questions...
It's not a secret anymore!