• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i restrict a servlet to create only one object

 
pankajjj jain
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i restrict a servlet to create only one object
through synchronize i can restrict to use only one object but
i want to create only one
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implemet the object as singleton, this will allow only one instance of this object.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pankajjj jain:
how can i restrict a servlet to create only one object
through synchronize i can restrict to use only one object but
i want to create only one


I agree to David.
By the way, one object of what?
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What functionality you want to achieve by this singleton Servlet?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Servlets forum.
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using classical singleton pattern in J2EE environment is not a good idea. It's a pain in the ass when the "singleton" might not be singleton as you might expected. One such situation might be when there exists a hierarchy of classloaders in different J2EE modules where each might load their own "singleton". You might face problem also when in distributable web application.

If you need to ensure real "singleton" object in your environment, an entity bean would do the trick.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic