For a local cache of read-only, non-persistence, non-secured data, with
fast access from each local Java instance, just do something like:

public class Repository {
  private static Hashtable stCache = null;
  public static Object getData(Object pkey) {
    if ( stCache == null ) {
      stCache = new Hashtable();
    }
    return stCache.get(pkey);
  }
  public static putData(Object pkey, Object pdata) {
    if ( stCache == null ) {
      stCache = new Hashtable();
    }
    stCache.put(pkey, pdata);
  }
}

// EJB code
...
mydata = Repository.getData(mykey);
if ( mydata == null ) {
  // initialize mydata
  mydata = ...;
  Repository.putData(mykey,mydata);
}
// use mydata�
...

Mind you, Repository is NOT an EJB, so it can have read-write
static fields. Any EJB can use it to store/fetch read-only,
non-persistence, non-secured data. This data is available for
all EJBs in the same JVM. No EJB rules are violated.

Regards

 Javier Borrajo
 www.tid.es


..





>This makes perfect sense - I suspect I encountered this confusion in the
first place
>because I thought session beans were aka. CORBA services/RMI objects, which
they
>aren't.  I guess not all things are possible with EJB's alone.
>
>Since I want this shared data to be a cache, therefore fast, therefore I
want it
>local- so RMI isn't really necessary. I just want a single class that's
accessable
>to all instances of my session bean - should I give up on this, since I'd
obviously
>need to do thread synchronization which is forbidden by the EJB spec?
>
>David
>
>Perry Hoekstra wrote:
>
>> David Michaels wrote:
>>
>> > Can you guys explain to me how this singleton idea works?  Since
session
>> > beans are not shared between simultaneous clients, I dont see how I can
>> > create just ONE of these for all clients to talk to - wouldn't multiple
>> > copies get created? I do want one of these per VM, but I don't think
>> > thats an issue since I'm using Weblogic and they pretty much keep
>> > everything in one VM as I understand.
>> >
>> > So is the singleton a class, (with static members, presumably against
>> > the EJB spec) or a bean, or what?
>> >
>> > I'm perplexed how this idea hasn't come up before - it seems to be an
>> > obvious thing to need to do (to cache data in the business logic layer
>> > so as to reduce load on the database (the central bottleneck)
>> >
>> > thanks!
>> >
>> > David
>>
>> If you check the archives, you will see a number of  discussions on
'singleton'.
>> The Cliff Notes version of the discussion is this: it is not possible
within EJB
>> beans.  So how do you it?  Depending on you poison preference, either an
RMI or
>> CORBA object bound into your JNDI (depending on vendor) tree would
suffice for a
>> singleton object.  There is no law that says that you cannot mix
distributed
>> object environments.
>>
>> --
>> Perry Hoekstra
>>
>> ---
>> "I don't see much sense in that," said Rabbit.
>> "No," said Pooh humbly, "there isn't. But there was going to be when I
began it.
>> It's just that something happened to it along the way."
>>
>>
===========================================================================
>> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
>> of the message "signoff EJB-INTEREST".  For general help, send email to
>> [EMAIL PROTECTED] and include in the body of the message "help".
>
>--
>David Michaels <[EMAIL PROTECTED]>
>Director of Technology
>ShockMarket Corporation (650) 330-4665
>
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to