This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance Issue because of connection handling

 
Gireesh Giri
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
1. I have implemented a web service with connection pooling(oracle-ds.xml) with JBoss server. In My business class, i am getting connection from pool and performing 4 to 5 DB operations, at last closing connection, statements and result set. It is working fine for one request.
2.If i tried for concurrent requests (Consider 5) only 1 or 2 processed, remaining failed with several reasons like (connection closed, statement closed, unusable connection, result set closed etc).
3.If i keep business class method as "synchronized" it is working fine. But it is serving only one request at a time (for concurrent request also). - This is slow downs my response time.

I came to know, This is connections problem, if one thread is doing DB operation, other thread is closing the connection or statement or result set.

Can any one help and tell me how to handle concurrent requests with out synchronized keyword.

Thanks in Advance.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to make sure that no 2 servlet threads use the same connection. You might have inadvertently done that if you are keeping the connection in a member variable that is shared between threads. This could be a static variable, or a member variable in your service class.

Can you post the skeleton of your code, or better yet come up with a SSCCE that replicates the issue.
 
Gireesh Giri
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jayesh,

Thanks for your replay. My webservice class looks like, Business class method i used synchronized to avoid connection problem

TestService.java
--------------------
{
private Business business;

public Business getbusiness() {
return business;
}

public void setbusiness(Business business) {
this.business= business;
}

business.validateMember() // business is the object wich i created using spring ioc, which is singleton false, below mentined the code snippet.
}

Business Class
--------------------
Business.java
--------------------

{

synchronized validateMember()

{

// java code.

}
}


application-context.xml

-------------------------------------

<bean id="business" class="org.core.Business" singleton="false">

<bean id="testService" class="org.core.TestService" singleton="false">

<property name="business"><ref bean="business"/></property>

</bean>
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you get the connection in your business class?

Since you are using spring, have you considered using favilities provided by spring. for example, using JPA annotations in your service class, or maybe using a jdbc template. Spring provides functionality that hides connection handling from you, and you just put the business logic in your code.
 
Gireesh Giri
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jayesh,
I am using jndi (JNDILookup.getObject("DATASOURCE_JNDI_NAME")) connection pooling not spring jdbc templates or jpa.

Just picking the connection from pool, and closing once my DB operation is done (connection.close()).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic