Hi,
I hope somebody can help me with a resolution to this issue.
Basically, if an impatient user happens to submit multiple times to the same
servlet, then
obviously threading problems will occur. For example the code snippet below
from Jason Hunter's book. Multple threads from the same user can arise
when he presses the submit button multiple times.
Threading switching occurrs after the execution of the
statement 'if(holder==null)' in the code below, then
there is a possibility for a null pointer exception when holder
is used.
How can this be prevented? ASP , I think only allows
one user thread per asp script. I think using synchronization
blocks within the servlet will be kill performance. How can I get
over this problem.
Any help on this matter is appreciated.
Thanks,
mmp.
----------------------------------------------------------------------------
-----
page 271 [ Chapter 9: Database Connectivity - Connections as Part of
Session]
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
ConnectionHolder holder = (ConnectionHolder)
session.getValue("servletapp.connection");
if(holder==null) {
try
{
holder = new ConnectionHolder
(DriverManager.getConnection("jdbc:oracle:oci7:ordersdb","user","password"))
;
session.putValue("servletapp.connection",holder);
}
catch (SQLException e)
{
getServletContext().log(e, "Could not get db connection");
}
}
Connection con = holder.getConnection();
try
Statement stmt = con.createStatement();
// transactions using con
}
// ...................
}
___________________________________________________________________________
To unsubscribe, send email to [EMAIL 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