The moose likes Struts and the fly likes How do actions queue requests? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How do actions queue requests?" Watch "How do actions queue requests?" New topic

How do actions queue requests?

Andrew DevSterMan

Joined: Nov 26, 2003
Posts: 6
I'm all hung up ...

I seem to have hit a problem with my struts application.

I am using -

1. Apache's Database Connection Pool.
2. The DAO pattern.
3. Tiles.
4. Tomact 5.0x

I have a problem where the Action classes, for say listing for a Client. This listing also searches for Jobs currently available for the client.

I have an action class that gets a client, and then gets the jobs for the client. All is well and good with this - it works beautifully, its succinct and easily maintained.

My problem comes with scalability. If I submit the http://localhost:8080/getClient.do?clientId=10 url from 2 or more browsers, they will all queue until the first comes back. It feels like the requests are queued up in the action.

Now I've looked around a lot, and have found very little by way of suggestions on how to fix this, or even acknowleding it.

I feel I am missing something here. I understand the action is a single instance, but should the threads not be running simulatenously? My DAO contains a reference to a simple datasource, which will freely give up connections to the DAOs, the processing doesn't seem to continue until the connection that came out first is returned to the pool.

Other Actions using the connection pool continue to function fine irrespective of the ClientAction being 'busy'.

Any directions would be gladly received.

I'm a bit desperate to fix this. I've seen something about ThreadLocal and filters, and I've also considered creating multiple copies of the action and giving them different names, but this seems very wrong indeed.



A carrot is as close as a rabbit gets to a diamond.
Cheenath Ajay
Ranch Hand

Joined: Jan 26, 2006
Posts: 32
I think nothing wrong with your Struts coding, may be you made some mistake in your DAO coding.

It will be easy if you can paste the database coding..

Andrew DevSterMan

Joined: Nov 26, 2003
Posts: 6
This is effectively what I have. The query is long a built on the fly.

Midway through, I also call another DAO that uses its own connection to do something.

package com.x.site.vacancy;

import java.sql.*;
import java.util.*;
import javax.sql.*;

import com.x.site.DAO.*;
import com.x.site.constants.*;
import com.x.site.logo.*;
import com.x.sql.*;
import com.x.utils.*;

public class OracleVacancyDAO
implements VacancyDAO {

public OracleVacancyDAO() {
System.out.println( "--- CREATION : a OracleVacancyDAO() " + this.toString() );

public boolean addVacancy() throws SQLException {

DataSource ds = null;
ds = OracleDAOFactory.getDataSource();
boolean returnBoolean = false;
Connection con = null;
con = ds.getConnection();

ResultSet rs = con.execute("SEELCT * FROM ....");
for ()
// Make a bean


return returnBoolean;
[ April 11, 2006: Message edited by: Andrew DevSterMan ]
Cheenath Ajay
Ranch Hand

Joined: Jan 26, 2006
Posts: 32
Ok little confusing, can you plz write two sop stats. before and after the DAO call?
and find out there is any delay in DAO,,

Cant you try that?

Cheenath Ajay
Ranch Hand

Joined: Jan 26, 2006
Posts: 32
Ok let me explain,

Any how there is no such reported bug in struts action.

So it can be because of ,

1. Problem in DBCP connection pooling mechanism
2. Or problem in DAO handling, like improper usage of synchronized methods or block.

Some humble advices,

1. I couldnt able to find a good exception handling or logging mechanism in your code, better try to make a use log4j in application for logging.
2. Hope you have cong DBCP in tomcat, no doubt the error report will be there in your Catalina log file( The delay may be because of more number of connection that your DB can provide).
3. .. check with all the above,

Hope for the best,

Andrew DevSterMan

Joined: Nov 26, 2003
Posts: 6

Thanks for your help.

You are right about error logging and the like, but deadlines, deadlines, deadlines.

I am now sure that the requests are queued up in one method call in my action class. I have worked around the problem by caching the data in the session, so that a single user pressing down F5 doesn't disable the site

I was hoping for some breakthough which meant a faster request would return first, even if dispatched after a slower one.

I have no Syncronization (added that is).

This isn't an error / exception, it is behavioural - faster requests for the same thing are queued behind slower requests.

[ April 11, 2006: Message edited by: Andrew DevSterMan ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
It has been my experience that defining data sources using the method recommended by the application server you are using is usually the best way to go. Granted, a framework data source is supposed to make your application more portable, but whether it really does is debatable.

I'd suggest you try defining the data Source using the recommended method defined in the Tomcat documentation, and then use JNDI to look up the data source. Then try again and see if you get the same problem. My guess is, you won't.

Another thing to check is the database itself. Have your DBA make sure it's allowing more than one simultaneous connection.

If none of this works, you may want to look into using a more "heavy duty" Application server such as WebSphere or WebLogic. I use data sources defined in WebSphere and stress testing of the applications indicates that the problem you mention is not occurring.

Consultant, Sima Solutions
Andrew DevSterMan

Joined: Nov 26, 2003
Posts: 6
Hi Merrill,

I can have up to 350 connections open. I presume these can be used concurrently. (DBA is away).

I am using the connection pool as a datastore configured in tomcat. It works beautifully for short snappy queries, and return them to the pool - indeed a standard page can make three of 4 queries, but holding down F5 on these the pool only needs the 5 or so connections, and then manages to recycle them. Its the more heavyweight queries that I have problems with.

I've stuck a fast a dirty cache (to prevent the user requesting the same data over and over from the database, which works).

I may try other application servers. You might be right. I understand that Tomcat is a reference implmentation.

Any recommendations on an enterprise server?. Ideally open source / free.

Many thanks

I agree. Here's the link: http://aspose.com/file-tools
subject: How do actions queue requests?
Similar Threads
How do you execute new code in an existing Thread?
How to make a data source connection without writing a User name & Password and the -ds.xml file
Connection Pooling
how to handle when huge number of requests are there?
Threads and Dread