users@glassfish.java.net

Accessing a datasource from a remote standalone client

From: <glassfish_at_javadesktop.org>
Date: Thu, 25 Mar 2010 05:47:48 PDT

Hi,
I have a simple java client application that connects to an Oracle database through an application server. My Client, Application Server and Database are all on different machines. I setup 2 examples: the first one with JBoss AS ver5, the other one with GlassFish v3 as the application server. The Client Application is more or less the same except th context initilization part.

Example 1 (Jboss) includes :
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
p.put(Context.PROVIDER_URL, "jnp://10.50.0.5:1099"); //ip of jboss server.

Example 2 (GlassFish) includes :
p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
p.setProperty("org.omg.CORBA.ORBInitialHost", "10.50.0.6"); //ip of glassfish server.
System.setProperty("org.omg.CORBA.ORBInitialHost","10.50.0.6");

Here (example.2), the third line is a little bit strange. I myself figured out to use it. It actually sets the environment variable of the client's JVM. Without that line, the code was broken while searching for the connection pool. The IP I set on the second line was being used to lookup the JDBC resource name. The system finds the jdbs resource and gets the connection pool name. But then the connection pool that is attached to the JDBC resource is being looked up in the localhost instead of the IP I supplied. I thougt it might be a bug and figured out that the parameter localhost comes from the client JVM's ORBInitialHost, so I added the third line and that worked.

As a result both examples worked and I could connect to database and run queries on them.

But there was something very strange. When I examine the database sessions, Example 1 created 4 sessions (min pool size I set on jboss) from the application server, while Example 2 created 4 sessions (again min pool size I set on glassfish) from directly client machine. furthermore; When I opened another instance of the client application, example 1 used one of the existing 4 sessions (which is the normal behaviour I expect from a connection pooling logic), but example 2 opened 4 more new sessions although the previous sessions still exist. Also direct connections of Example 2 run quite faster than that of example 1.( which was actually the point of origin of my concerns)

Please someone shed a little light on this subject.
[Message sent by forum member 'ardaustun']

http://forums.java.net/jive/thread.jspa?messageID=393709