Okay everyone I really need some help here.  We have an issue that I think I
have seen before, but I can't seem to find it in the newsgroup or archives.
Currently we have a ColdFusion server running on our front end(try not to
laugh too hard) and Orion running in the back.  We created a LoginBean Class
which resides on the ColfSusion server and validates username and password
via a session bean on the orion server.  This works great until two people
try to login at the same time(i.e. the second tries to login before the
first completes the process.) When this occurs, the first one to hit the
site gets validated and the second throws:

 NamingException: unable to instantiate
com.evermind.server.ApplicationClientInitialContextFactory.

hen our LoginBean instantiates it calls a private method called
getJndiContext() which sets it's member variable jndiContext for use within
the class. This is where the error is occuring.

  private void getJndiContext()
  {
    //get the context
    if(jndiContext == null)
    {
      try
      {
        jndiContext = new InitialContext(); <<<<<---------!!!!! ERROR Occurs
Here !!!!!
        userHome = (UserHome)
PortableRemoteObject.narrow(jndiContext.lookup("User"),UserHome.class);
        profileHome = (ProfileSessionHome)
PortableRemoteObject.narrow(jndiContext.lookup("ProfileSession"),ProfileSess
ionHome.class);
      }
      catch(NamingException ne)
      {
        Log.txt(this, "Naming Exception:" + ne.getMessage(), LOGFILE);
        ne.printStackTrace();
      }
    }
  }

I believe the rest of the class is unsbstantial when dealing with this
issue.

So then I thought it could not create multiple instances of the same object
on the cold Fusion side. So, I created a teb object that implemented
Runnable and created a New LoginBean for each instance thinking it would
work locally but not in Cold Fusion.

here is the code for the test object:

import java.rmi.RemoteException;
/** User is an EJB containing user information(i.e. First Name, Last Name,
email, etc...) */
import com.we.api.profile.User;

public class RunnableLoginBean implements Runnable
{
    LoginBean login;
    StringBuffer sb;

  public RunnableLoginBean()
  {
    this(null,null);
  }

  public RunnableLoginBean(String u, String p)
  {
    login = new LoginBean();
    login.setUserName(u);
    login.setPassword(p);
    sb = new StringBuffer();
  }

  public RunnableLoginBean(String u, String p, StringBuffer sb)
  {
    this.sb = sb;
    login = new LoginBean();
    login.setUserName(u);
    login.setPassword(p);
  }

  public void run()
  {
    if(login.isUserValid())
    {
      try
      {
        sb.append("Hello :" + login.getUser().getFirstName() +"\n");
      }
      catch(RemoteException re)
      {
        sb.append("Error: " + re.getMessage());
        re.printStackTrace();
      }
    }
    else
    {
      sb.append("Login failed for :" + login.getUserName() +"\n");
    }
  }

  public String test(int count)
  {
    for(int i=0; i < count;i++)
    {
      Thread t1 = new Thread(new RunnableLoginBean("jhogan","password",
this.sb));
      t1.start();
    }
    try
    {
      Thread.sleep(5000); //make sure the threads are done before
printing....
    }
    catch(Exception e)
    {
      sb.append("Error waiting:" + e.getMessage());
      e.printStackTrace();
    }
    return this.sb.toString();
  }

  public static void main(String[] args)
  {
    RunnableLoginBean lb = new RunnableLoginBean();
    System.out.println(lb.test(10));
  }
}

This works fine on both my machine and the cold fusion server.  But if 2
users hit the same page at the same time(i.e. the second hits before the
first is finished), all ten(10) of the first connector's tests pass, and all
ten(10) of the second connector's tests throw the instantiation error. I
seem to remember seeing this problem with JRUN before.  Since JRun and
ColdFusion are built by the same company I am assuming right now they may
use the same code for session/object storage and thus the problem may happen
on both platforms. It's almost as if they have a Singleton Hashtable of
classes per object call and thus cannot instantiate more than one instance
of a class per application call. 


I am at a loss as to why this would happen.  Any ideas on why this is
happening and what we can do to fix it? 

Thanx in advance

Greg

Reply via email to