You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jerry Jalenak <Je...@LABONE.com> on 2002/08/19 18:14:15 UTC

HELP!!! Web App hangs after repeated queries....

I hope someone can point me in the right direction on how to resolve the
following issue.  Our environment is

	Windows NT (Service Pack 5 and 6); have also seen this on Solaris
5.8
	Apache 1.3.26
	Tomcat 3.3.1
	Struts 1.1 Beta 2
	Java 2 SDK 1.4.0_01

We have an application that access data from an Oracle 8.1.7 DB based on
various user input.  After about 15 or 18 queries, the application appears
to 'hang' - i.e. nothing ever ends up coming back.  When I stop Tomcat, I
get the following stack trace (could be due to stopping Tomcat - I'm not
sure):

Error: 500
Location: /aefa/QueryRecordAction.do
Internal Servlet Error:
java.lang.NullPointerException
	at
org.apache.struts.action.RequestProcessor.getServletContext(RequestProcessor
.java:1076)
	at
org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRe
questProcessor.java:175)
	at
org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequ
estProcessor.java:291)
	at
org.apache.struts.action.RequestProcessor.processActionForward(RequestProces
sor.java:390)
	at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:271)
	at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
	at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java)
	at
org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
	at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
	at org.apache.tomcat.core.Handler.service(Handler.java:235)
	at
org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
	at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:91
7)
	at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
	at
org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Int
erceptor.java:341)
	at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
	at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:516)
	at java.lang.Thread.run(Thread.java:536)

I've monitored the memory usage on WinNT using the task manager; each query
results in an increase in memory usage of between 300 and 400k.  I don't
ever see any memory being reclaimed (this is under the 'java' task which is
Tomcat.)  QueryRecordAction does a SELECT, then builds a nested bean to hold
the returned 'rows' - the is another bean that holds the actual data.  The
code for the two beans is

	Results.java

		public class Results {
			private Vector results;

			public Results() {
				this.results = new Vector();
			}

			public Vector getResults() {
				return this.results;
			}
			public void addRow(Row row) {
				this.results.add(row);
			}
			public void clear() {
				this.results.clear();
			}
		}

	Row.java

		public class Row {
			private String name;
			private String address;  // etc. etc. etc.

			public Row() {
				this.name = "";
				this.address = "";
			}
			/* normal getters */
			public String getName() {
				return this.name;
			}
			public String getAddress() {
				return this.address;
			}
			/* normal setters */
			public void setName(String name) {
				this.name = name;
			}
			public void setAddress(String address) {
				this.address = address;
			}
		}

QueryRecordAction cleans up the previous set of beans (if they exist), then
rebuilds the beans and puts the bean back into the session.

	QueryRecordAction

		public class QueryRecordAction extends Action {
			PreparedStatement ps = null;
			ResultSet rs = null;

			public ActionForward execute(ActionMapping mapping,
ActionForm form, HttpServletRequest request, HttpServletResponse response) {
				HttpSession session = request.getSession();
				if (session.getAttribute("results") != null)
{
					Results results = (Results)
session.getAttribute("results");
					results.clear();
					session.removeAttribute("results");
				}

				Results results = new Results();

				String queryName = (String)
PropertyUtils.getSimpleProperty(form, "queryName");
				try {
					DataSource ds = (DataSource)
servlet.getServletContext().getAttribute("AEFA");  // key for datasource in
struts-config
					Connection con = ds.getConnection();
					ps = con.PrepareStatement("SELECT
name, address from aefa_order where query_name = ?");
					ps.setString(1, queryName);
					rs = ps.executeQuery();
					while(rs.next()) {
						Row row = new Row();
	
row.setName(rs.getString("name"));
	
row.setAddress(rs.getString("address"));

						results.addRow(row);
					}
					session.setAttribute("results",
results);
					rs = null;
					ps = null;
					con = null;
					ds = null;
				}
				catch(Exception e) {
					ActionErrors errors = new
ActionErrors();
					errors.add("internal_error", new
ActionError("internal.error", e.getMessage()));
					saveErrors(request, errors);
					return
(mapping.findForward("error"));
				}
				return (mapping.findForward("success"));
			}
		}

The "success" forward displays a table of all the rows that were returned.
Everything works just like I would expect it to, except for Tomcat hanging
after 15 or 18 queries.  I've been through the code and can't find where I
would have a memory leak - if anyone can spot one, or has other ideas,
please let me know!

Thanks!


Jerry Jalenak
Web Publishing
LabOne, Inc.
10101 Renner Blvd.
Lenexa, KS  66219
(913) 577-1496
jerry.jalenak@labone.co


This transmission (and any information attached to it) may be confidential and is intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient or the person responsible for delivering the transmission to the intended recipient, be advised that you have received this transmission in error and that any use, dissemination, forwarding, printing, or copying of this information is strictly prohibited. If you have received this transmission in error, please immediately notify LabOne at (800)388-4675.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: HELP!!! Web App hangs after repeated queries....

Posted by Melissa L Kelley <st...@stuology.net>.
On Mon, 19 Aug 2002, Jerry Jalenak wrote:


Chances are you are not releasing your database resources correctly. I may
be wrong, but you should explicitly close your statement, resultset, and
connections using the close() method instead of setting them to null. You
can use the isClosed() method of your connection to check that it really
is being closed.

Plus, it is generally a good idea to close them in a finally clause to
make sure they are closed even when an Exception is thrown.



--> stu: www.stuology.net
It just no longer is plain simple safe fun
when it's the psycho chimp that has the ray gun
------------------------------------------------
Stuology -- A million monkeys can't be wrong


> I hope someone can point me in the right direction on how to resolve the
> following issue.  Our environment is
>
> 	Windows NT (Service Pack 5 and 6); have also seen this on Solaris
> 5.8
> 	Apache 1.3.26
> 	Tomcat 3.3.1
> 	Struts 1.1 Beta 2
> 	Java 2 SDK 1.4.0_01
>

[cut to preserve space]

>
> QueryRecordAction cleans up the previous set of beans (if they exist), then
> rebuilds the beans and puts the bean back into the session.
>
> 	QueryRecordAction
>
> 		public class QueryRecordAction extends Action {
> 			PreparedStatement ps = null;
> 			ResultSet rs = null;
>
> 			public ActionForward execute(ActionMapping mapping,
> ActionForm form, HttpServletRequest request, HttpServletResponse response) {
> 				HttpSession session = request.getSession();
> 				if (session.getAttribute("results") != null)
> {
> 					Results results = (Results)
> session.getAttribute("results");
> 					results.clear();
> 					session.removeAttribute("results");
> 				}
>
> 				Results results = new Results();
>
> 				String queryName = (String)
> PropertyUtils.getSimpleProperty(form, "queryName");
> 				try {
> 					DataSource ds = (DataSource)
> servlet.getServletContext().getAttribute("AEFA");  // key for datasource in
> struts-config
> 					Connection con = ds.getConnection();
> 					ps = con.PrepareStatement("SELECT
> name, address from aefa_order where query_name = ?");
> 					ps.setString(1, queryName);
> 					rs = ps.executeQuery();
> 					while(rs.next()) {
> 						Row row = new Row();
>
> row.setName(rs.getString("name"));
>
> row.setAddress(rs.getString("address"));
>
> 						results.addRow(row);
> 					}
> 					session.setAttribute("results",
> results);
> 					rs = null;
> 					ps = null;
> 					con = null;
> 					ds = null;
> 				}
> 				catch(Exception e) {
> 					ActionErrors errors = new
> ActionErrors();
> 					errors.add("internal_error", new
> ActionError("internal.error", e.getMessage()));
> 					saveErrors(request, errors);
> 					return
> (mapping.findForward("error"));
> 				}
> 				return (mapping.findForward("success"));
> 			}
> 		}
>
> The "success" forward displays a table of all the rows that were returned.
> Everything works just like I would expect it to, except for Tomcat hanging
> after 15 or 18 queries.  I've been through the code and can't find where I
> would have a memory leak - if anyone can spot one, or has other ideas,
> please let me know!
>
> Thanks!
>
>
> Jerry Jalenak
> Web Publishing
> LabOne, Inc.
> 10101 Renner Blvd.
> Lenexa, KS  66219
> (913) 577-1496
> jerry.jalenak@labone.co
>
>
> This transmission (and any information attached to it) may be confidential and is intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient or the person responsible for delivering the transmission to the intended recipient, be advised that you have received this transmission in error and that any use, dissemination, forwarding, printing, or copying of this information is strictly prohibited. If you have received this transmission in error, please immediately notify LabOne at (800)388-4675.
>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>