----- Original Message -----

> From: Terence M. Bandoian <tere...@tmbsw.com>
> To: Tomcat Users List <users@tomcat.apache.org>
> Cc: 
> Sent: Thursday, December 15, 2011 11:31 AM
> Subject: Re: dbcp is mixing up connections
> 
> On 1:59 PM, Christopher Schultz wrote:
>>  Aitor,
>> 
>>  On 12/15/11 7:12 AM, Aitor Garcia | Tempel.es wrote:
>>  > 5) Tomcat, creates ONE (or maybe SOME) Class object and call to the
>>  >  _jspService on every script request
>> 
>>  > What happens if you handle Pool Coonections with a
>>  > 'java.sql.Connection conn' variable declared into the 
> definitions
>>  > block "<%! %>"?
>> 
>>  > Happens than if you are donig multitheading and executing the same
>>  > sctipt in parallel you will mix up connections because evey thead
>>  > is executing the same method in parallel and putting a different
>>  > connection into the java.sql.Connection conn class variable.
>> 
>>  > I don't know if this is a tomcat bug.
>> 
>>  Obviously it's not.
>> 
>>  This is one of the many reasons why application logic has no business
>>  being in a JSP. Whoever proposed (and, indeed approved) the
>>  introduction of scriptlets (<% ... %>) should have been flogged.
>> 
>>  -chris
> 
> Hi, Chris-
> 
> From the Java Server Pages Specification:
> 
> "There are three language-based types of scripting elements:
> declarations, scriptlets, and expressions. Declarations follow the
> syntax <%! ... %>. Scriptlets follow the syntax <% ... %>. 
> Expressions
> follow the syntax <%= ... %>."
> 
> -Terence Bandoian
>

Lots of things are causing problems here.

As many others have pointed out, instance variables are not thread safe. In 
short, do not put your business logic, database logic, or control logic in a 
JSP page. You will have problems.

I suggest reading at least two books (plus the servlet spec as others have 
recommended).

Head First Servlets and JSP by Bryan Basham, Kathy Sierra, and Bert Bates

I've read the first edition. The second edition is out and highly reviewed. It 
covers a lot of material in a very approachable way. It does have a chapter at 
the end on MVC, but it is not a design book.

Several people have mentioned the Design Patterns book by the Gang of Four 
(Gamma et. al). It's a great book, but you may or may not find it approachable.

Head First Design Patterns by Freeman and Freeman is another approachable book, 
with examples and exercises in Java. It obviously covers design patterns. Even 
Erich Gamma was impressed (according to the "praise page").

Finally, I took a look at the library you're using to do logging. It appears 
that what you are trying to do is not supported. See the following two links:

http://code.google.com/p/log4jdbc/wiki/FAQ

http://code.google.com/p/log4jdbc/wiki/DataSourceExampleForWebSphere


In short, it appears that without writing your own factory, you will not get 
the results you want with this library. Granted, I've not really explored the 
code that much so I could be completely wrong here.

I do not have any affiliation with any of the books or authors mentioned. I 
just have found them good learning resources.

just my two cents . . . .
/mde/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to