• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to store the handle for the delegate

 
sandeepc chintaki
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ,
I am using delegate pattern to call the EJB services.
I am instantiating the delegate class everytime a call is made by the client which I am not satisfied doing this as it would create n number of objects for n calls.

how should I store the single instance of the delegate class ?

Thanks for the guidance.
Sandeep
 
Vinay Raj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest solution for your requirement is to use singleton pattern. However I would recommend that you create a new object of the business delegate object every time you need to interact with the EJB services. If you go the singleton route, you will need to ensure that your singleton implementation is thread safe.

Creation of new objects in the current JVMs is no longer expensive, my recommendation would be not to change current implementation.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would agree about staying away from using a singleton. If the Java Gods wanted this to be implemented as a singleton, it would have been built into the spec. I really doubt that your code is creating as much of a performance impact as you are concerned about.

The other thing you really have to worry about is creating singletons in a J2EE environment with a crazy number of classloaders. People are often amazed when I profile their JVMs, and show them how many instances of their 'singleton' class is running on their server.

A simple, GOF singleton isn't sufficient in most J2EE environments.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!