Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Managing lifecycle of servlets  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Does there exists features in the current opensource/commercial appservers that would allow you to manage the lifecycle of individual servlets ?
By "management", I mean I want to be able to stop/start a servlet - i.e. equivalent to calling destroy/init respectively. When the servlet is "stopped", accessing the url mapped to the servlet should flag a 404. I've read this Invoker Servlet Thread but it doesn't seem to provide a definite answer.

On the top of my head, one way would be to archive one servlet in its own individual war file. Then one would be able to deploy/undeploy the war - effectively doing the start/stop in a crude way. Hope to hear from users of commercial appservers like BEA, Oracle etc.. Thanks a lot everyone.

Regards,

Pho
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know of no server that would such functionality. And I'm not sure why any would -- it's a really odd thing to want to do.

What are you really trying to accomplish? I'm sure a supported means to do what you really need can be devised.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

I need to have fine grained control on the lifecycle of servlets (from an administrative perspective). I don't think it's an odd request at all. Currently if I wanted to disable a servlet for a short amount of time, I would need to deactivate the whole war/ear, modify the web.xml, then redeploy. Then when I want to RE-ENABLE the servlet, I would need to redo the shtick again. Seems very inflexible to me.

Regards,

Pho
[ February 19, 2007: Message edited by: Pho Tek ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to have fine grained control on the lifecycle of servlets (from an administrative perspective).


Well then create your own administrative servlet as part of the web application. This servlet would manage a resource held in the application context which would control and monitor all the public servlets in the context. In addition to switching servlets on and off it could count accesses, monitor response time, etc etc.
Before responding to a request, a public servlet would check this shared resource to see if it currently allowed to run.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to explore the concept of filters or the Front Controller pattern.

Breaking each servlet up into its own web application would be folly.
 
Tim Holloway
Bartender
Posts: 18705
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could simply make a new servlet base class that implemented its own start/stop functionality via a special HTTP or JMX request.

Normally, however, I expect servlets to be supporting components of an app, not business units in their own right. So about the closest I get is starting and stopping application subsystems. To do otherwise for me would be the same as starting and stopping classes.

And, of course, neither servlets nor classes are thread objects (OK, so java.lang.Thread and descendents are exceptions), so actually starting and stopping a servlet isn't technically possible - all you can do is either stop passing it requests or make it reject the requests it does get.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!