Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes 15 DataSource Connections in JSP vs 45 in Java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "15 DataSource Connections in JSP vs 45 in Java class" Watch "15 DataSource Connections in JSP vs 45 in Java class" New topic
Author

15 DataSource Connections in JSP vs 45 in Java class

Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Hello

Java class returns 45 database connections and same code in JSP returns 15 connections. Here is what I am trying to do.

I have created a DataSource in WebLogic. The Maximum connection capacity is set to 15. I have created three managed servers clustered and I have targeted the DataSource to all three Managed servers in the cluster. I have a java class (client) which requests database connection in a loop and it stops/errors-out when the total number of connections reaches 45 (15 connections each provided by the three Managed Servers in the cluster). When I put the same code in the JSP, I only get 15 connections max. I am not sure what is wrong.

Here is the code - please excuse me for the quality of code. This code is not mine. I am trying to investigate why the DataSource connection count stops at 15 in the JSP.

========== Java Class Start =============

========== Java Class End =============

========== JSP Start =============

========== JSP End =============

Any clues?

Regards
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30370
    
150

Saeed,
Obviously both of those aren't closing connections between attempts so it looks like you are intentionally trying to exhaust resources. The problem is that it isn't a realistic test. When real users access your JSP, they will presumably load balanced to all three servers rather than competing for the same 15 connections. Because of this, there is no reason for the server to allow sharing connections across servers. I'm guessing the client has something that does.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Yes the "closing connection" part has been intentionally left out.

I am wondering why the two (Java Class and the JSP with same code) are behaving differently?

Best regards

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30370
    
150

How exactly is the Java class one being called?
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
From command line like this:



Regards
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2380
    
    7

Setting the connection variable to "null" (line 38) is not the same as closing it. Doing so is really waiting for the GC to kick in. But since you are using connection pool (right?), not closing connection means that connection WILL NOT go back to the pool.

Also if there is an exception you are closing it (line 49). Instead, the closing part should be in finally block.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Thanks Tsang but that does not address/answer the question I have.

I am expecting the code both in JSP and the Java class to get same number of connections - regardless of what happens with them later.

I am not sure JSP is getting 15 connections (instead of 45) due to some setting in WebLogic configuration.

Regards
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2380
    
    7

How is the datasource setup in Weblogic?

Maybe look at those advanced parameters in the doc, setting those may help
http://docs.oracle.com/cd/E15051_01/wls/docs103/ConsoleHelp/pagehelp/JDBCjdbcdatasourcesjdbcdatasourceconfigconnectionpooltitle.html
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2342
    
  28

What are you trying to prove/solve here? You have bad code that is subject to the vagaries of GC and the connection pool. Many times the connection pool will detect orphaned connections, and close them. Or the database might detect an idle connection, close it, and the pool will discard it. It entirely depends on how sophisticated the connection pool is. By not explicitly closing the connection, you are subjecting the system to too many unknown factors that you have no control over.

Say, if you did find out why JSP is able to open more connections, what will you do with that knowledge? How is it going to help you? It might be an interesting exercise, but how does it help you?

I have a stupid hunch. I bet the memory settings in your 2 test beds are completely differrent. And I bet that GC runs more often when you run this test in a Java app. And I bet the connection pool has something that returns the underlying connection back to the pool in the finalize method. If all of the above are true, then GC might be returning the orphaned connection back to the pool more often in the Java app. WHich is why you can open more connections.

Do an experiment:- Increase the memory given to the Java app, and run the test again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 15 DataSource Connections in JSP vs 45 in Java class