• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

EJB: where to store an instance that must be available to every EJB?

 
Ranch Hand
Posts: 157
Netbeans IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello:

I'm developing an EJB application that needs to read a configuration file on its deployment. I want to read several parameters from that file and instantiate an immutable object that store or hold such values. Then I want to share this instance across all the existing EJBs. I should be able to use this instance on any method of that EJBs. I want to keep this instance restricted to the scope of the EJB module because it contains information that it's private, so I can't pass it as an argument to the methods.

I'm planning to use a shared single instance because conceptually there is "one configuration" only, so it makes sense in my opinion. Correct me if I'm wrong.

In some way I want something equivalent to the concept of javax.servlet.ServletContext in the "servlet world" which, among many other things, allows to store global attributes.

Is there something similar that I can use in EJB 3.0 and 3.1? For EJB 3.1 I've read that you can inject a javax.ejb.EJBContext object into your EJBs and get/set data through the java.util.Map returned by the method context.getContextData () . Is this right? What about EJB 3.0?

By the way, to achieve the global availability of this instance in the past, I used the singleton implementation explained in the book "Design Patterns". However I've been convinced that this is not the way to go and that's why I'm changing my strategy.

Thank you.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I usually create a

@Singleton
public class SingletonBean { ... }

Why not convinced?
 
Avor Nadal
Ranch Hand
Posts: 157
Netbeans IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Francesco: first of all, thank you for answering.

It's not that I'm not convinced, he he he. I was just looking for a solution that worked in EJB 3.0 too. Because I've several projects running with that version and would like to use the same methodology.

Anyway, I believe that I'm going to keep the classic singleton implementation from "Design Patterns" in my EJB 3.0 projects, whereas I'm going to use the new Singleton bean in my EJB 3.1 projects.

Salutes ;) .
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic