> > 1) What is a singleton? Is it one instance per classloader, one
> per JVM or
> > one per a cluster of machines?
>
> once per classloader. If you want to go beyond that you need another
> mechanism (it's just not possible within Java otherwise, as you need
> "static").
>
> > 2) This is similar to the root component manager issue (Berin
> > brought up the
> > fact that there are some security risks involved and that JNDI would be
> > safer), and I think a solution within that framework would be better. It
> > would also answer the first question.
>
> JNDI should be optional, methinks. So a JNDI-stored single-instance-only-
> objects-framework should be only ever an optional part.

Then the following is possible:

Per CL:

Component implements ThreadSafe and passes all messages on to a private
static final instance:

public class CLSingleton implements ThreadSafe {

  private static final CLSingletonService instance = new CLSingletonService
();

  public void doStuff() {
    instance.doStuff();
  }
}


Per Cluster:

Component is poolable and looks up the remote object in initialize() and
recycle():

public class ClusterSingleton implements Poolable, Recyclable,
Initializable, Disposable {

  private ClusterSingletonService instance = null;

  public void doStuff() {
    instance.doStuff();
  }

  public void initialize () {
    instance = doJNDILookup ();
  }

  public void dispose () {
    disposeInstance ();
  }

  public void recycle () {
    // To avoid memory leaks via RMI, dispose and lookup the JNDI instance.
  }
}

So both types of singletons are possible without a new Singleton interface.

/LS


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to