Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
Need help with servlet thread safety...

Need help with servlet thread safety...

2005-04-11       - By Brett Zamora

 Back
Reply:     1     2     3     4     5     6     7  

Hi...

I'm trying to build a JSP/Servlet application that will retrieve, add,
update, and delete records from a database. I've recently encountered some
of the complications that can be seen if a servlet is not written to be
thread safe.

First I'd like to say that I've been reading and reading on this issue and I
thought I had a pretty good grasp on the subject, however, I still cannot
eliminate the condition I am experiencing.

The problem I'm seeing is when I first start up my application server,
either Tomcat or Resin, and I run my application, which retrieves records to
be displayed from the database, invalid data is displayed in some of the
fields. Basically, the instance variables for the bean class are being
trashed.

I can only create this condition the first time after I stop and restart the
application server. After the first occurrence, it does not seem to
continue. This doesn't mean the condition doesn't exist, just that I can't
seem to recreate it.

I have set up a sample of the problem at http://www.zware.net/simpleDemo

It is a very basic, very small sample amount of code that does what I
outlined on the simple demo page. I've also provided the source code, so
that anybody that might be willing to help me, could see how I am attempting
to synchronize my code to avoid the condition I am seeing.

In a nutshell, I create a bean for the user record. I then synchronize the
bean and call a method to retrieve the data. Before exiting the synchronize
block, I add the bean to the session object. I then exit the synchronize
block and forward control to the jsp page to display the data.

As I said, I can only cause the condition to occur in a very specific way,
however, I'm inclined to believe that I'm doing something drastically wrong
and I am afraid to continue developing anything until I completely
understand how to avoid the multi-threading problem that I seem to be
experiencing.

I would appreciate any feedback that anybody could provide on what I've done
wrong. Please don't slam me for code structure. This simple app was put
together to be readable and to solicit some assistance with my
use/understanding of how to synchronize an object.

Synchronization seems pretty straight-forward, conceptually, however, I
cannot resolve this issue. I've even gone so far as to use the implements
SingleThreadModel on the SimpleCtl class, but this still does not resolve
the condition.

I'm wondering if it could be my JDBC driver? My backend database is MySql
and I've tried a couple of version 3.x JDBC drivers, but again, I cannot
resolve the problem.

Any help is greatly appreciated.

Regards,

Brett

Sample: http://www.zware.net/simpleDemo

__ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ __
To unsubscribe, send email to listserv@(protected) and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

©2008 junlu.com - Jax Systems, LLC, U.S.A.