Hi.
  A working model is to create two Initial Context-s for each server.
  Use a "dedicated.connection=true" property to create the context.
  The "dedicated.connection" however leads to resource leakage, and if you
keep creating more and more of them you will eventualy get
"java.lang.OutOfMemoryError: Can not create native thread" at some 200-300
contexts.
  If you create an context for both servers, and then use them later you
might not have this problem.

  public static Context[] connections;

  public void ejbCreate(){
    if ( connections != null ) return;
    Hashtable env = new Hashtable();

    // Use any of these.
    env.put("dedicated.connection", Boolean.TRUE );
//    env.put("dedicated.connection", "true");

    // Set up user, pass,
    // factory (RMIInitialContextFactory).
    env.put(".......", "...."); // Set up things

    connections = new Context[2];

    // For The first server
    env.put(Context.PROVIDER_URL, "ormi://Comp1/App1");
    connections[0] = new InitialContext(env);

    // Now for the other server
    env.put(Context.PROVIDER_URL, "ormi://Comp2/App2");
    connections[1] = new InitialContext(env);
  }

  public void connectServer1(){
    connections[0].lookup("MyBean1");
  }
  public void connectServer2(){
    connections[1].lookup("MyBean2");
  }

   You DO understand this is Orion-specific, right?

  Good luck. Lachezar.

> I've got the same beans deployed on two different app servers (each
> backed by a different database). I want my client to talk to both.
> Say the two app servers are running on machines named Fred and Wilma;
>
> I know I can choose which one I talk to by setting
>
>   java.naming.provider.url=ormi://fred/app
>
> or
>
>   java.naming.provider.url=ormi://wilma/app
>
> But how do I switch at run time? I don't want to keep changing the
> system property every time I get an InitialContext(), because the
> system property is a global setting and one piece of code might not
> know what another piece of code is doing. Is there a way to specify
> the JNDI url when you create an InitialContext?
>
>
>


Reply via email to