Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A couple of init() questions...

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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?

Thanks,
James
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

-Ben
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Cheers,
James
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic