-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander,

On 2/2/2010 2:44 PM, Alexander Hartner wrote:
> I have developed an application which accesses a database via
> Hibernate as well as directly via JDBC (datasource). The datasource is
> defined in the server.xml file as follows:
> 
>     <Context path="" docBase="AddressBookServer.war">

:(

Put this into either META-INF/context.xml within your WAR/webapp
directory, or into CATALINA_BASE/Catalina/[hostname]/ROOT.xml

Remove the "path" and "docBase" attributes when you move the <Context>
element.

>           <Environment name="LicenseFile" value="Licensekey.license" 
> type="java.lang.String" override="true"/>         
>           <Environment name="BackupsFolder" value="../backups" 
> type="java.lang.String" override="true"/>       
>  
>           <Resource name="jdbc/AddressBookDB" auth="Container" 
> type="javax.sql.DataSource"
>              maxActive="25" maxIdle="5" maxWait="-1" removeAbandoned="true" 
> removeAbandonedTimeout="60" logAbandoned="true"
>              username="sa" password="" driverClassName="org.h2.Driver"
>              
> url="jdbc:h2:tcp://localhost:28081/../db/AddressBookDB;LOCK_TIMEOUT=60000"/>

That URL looks fishy, with ".." in its name. It that a relative disk
path? If so, you're asking for deployment headaches in the future.

>           <Realm className="org.apache.catalina.realm.JDBCRealm"
>             driverName="org.h2.Driver"
>             
> connectionURL="jdbc:h2:tcp://localhost:28081/../db/AddressBookDB;LOCK_TIMEOUT=60000"
>             connectionName="sa" connectionPassword=""
>             userTable="WEBUSERS" userNameCol="USERID" userCredCol="PASSWORD"
>             userRoleTable="WEBROLES" roleNameCol="ACCESSROLE"/>

Consider using DataSourceRealm instead of JDBCRealm: JDBCRealm uses a
single Connection object (thereby serializing logins) and has had a
bunch of concurrency issues in the past. DataSourceRealm can use your
previously-configured DataSource for Connections. Or, you can define an
authentication-only DataSource that is used only by the DataSourceRealm.

> By default I use an embedded H2 database and everything works great.
> The numActive count goes up during activity and decreases to 0 when
> there is no activity. Also the count generally matches the actual
> connections to the database as one would expect. If I use the same
> application with PostgreSQL 8.4 however, the numActive count goes up and
> up, and only sometimes down. Generally sitting around 25 even though
> PostgreSQL only reports 4 idle connection.
> 
> I already tried adding the following to my datasource configuration,
> however this did not make any difference so far.
> removeAbandoned="true" removeAbandonedTimeout="60"
> logAbandoned="true"

Did you look at your log files after setting these parameters?

> I am using Tomcat 6.0.18 on OS X 10.6.2 with Java 1.6.
> 
> Any suggestion on how I can debug this further why Tomcat reports an
> incorrect numActive count and eventually runs out of possible
> connections. Currently it has to be restarted several times a day with
> PostgreSQL.

While there are other possibilities, you might want to read this:
http://blog.christopherschultz.net/index.php/2009/03/16/properly-handling-pooled-jdbc-connections/

I would /highly/ recommend running with maxActive="1" in all
environments except for production, as you will likely trigger any
Connection leaks much more quickly that way.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktoq7QACgkQ9CaO5/Lv0PCUzwCgrDZffO+r8bHFsYLbwelii0mC
rlgAoIfO6KH1IDzEZawRyHyW7+gKRdnD
=zA4A
-----END PGP SIGNATURE-----

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

Reply via email to