• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Can we make " singelton servlet" ?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi EveryBody,
I am new member of this group.

I want to know that :

Can we make "singelton servlet" ?
If Yes . then how can we write this type of servlets.
pls mention it.

Thanks & Regards:
Anand Rai
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a normal servlet container, there is only one instance of a servlet class for a particular web application. I suppose that could be called a "singleton."
Learning how to program for the situation where any number of requests can "simultaneously" be processed by that one instance is the big jump you have to make from programming single user applications.
Bill
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Learning how to program for the situation where any number of requests can "simultaneously" be processed by that one instance is the big jump you have to make from programming single user applications.



I am not sure which is easier. Personally writing servlet is more obvious for me than programming standalone Swing application. I think that is because servlets do put a lot of constraints on programmer, while there is much freedom in single user applications. Freedom = thinking = reinventing wheels = time = -money
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by anandbhucs rai:
Can we make "singelton servlet" ?



Yes you can, although a much more important questions is should you do it. No you definitely should not.

Servlet containers are required to manage Servlet instances internally, and there are a few different requirements it needs to meet. If you make a Servlet a Singleton it will prevent the Servlet container for working correctly.
 
author
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anand,

Maybe you could explain why you want a singleton servlet - what is the requirement driving you towards a singleton servlet as a solution?

Apart from David O'Meara's point (you shouldn't try to force servlets to be singletons, or you may break the web container), singletons in general become difficult or impossible to manage if you decide to make your web application distributed.

Best,

David.
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic