Cannot get a connection, pool exhausted
Hello, i'm trying to achieve DBCP with tomcat 5.5.9. I thought to have done things right since the application could connect to db, but after a night that the application was running, in the morning, in logs, i saw a lot of Cannot get a connection, pool exhausted errors. This is my configuration: SERVER.XML: Server port=8005 shutdown=SHUTDOWN Listener className=org.apache.catalina.mbeans.ServerLifecycleListener / Listener className=org.apache.catalina.mbeans.GlobalResourcesLifecycleListener / Listener className=org.apache.catalina.storeconfig.StoreConfigLifecycleListener / GlobalNamingResources Environment name=simpleValue type=java.lang.Integer value=30 / Resource name=UserDatabase auth=Container type=org.apache.catalina.UserDatabase description=User database that can be updated and saved factory=org.apache.catalina.users.MemoryUserDatabaseFactory pathname=conf/tomcat-users.xml / /GlobalNamingResources Service name=Catalina Connector port=8080 maxHttpHeaderSize=8192 maxThreads=150 minSpareThreads=25 maxSpareThreads=75 enableLookups=false redirectPort=8443 acceptCount=100 connectionTimeout=2 disableUploadTimeout=true / Connector port=8009 enableLookups=false redirectPort=8443 protocol=AJP/1.3 / Engine name=Catalina defaultHost=localhost Realm className=org.apache.catalina.realm.UserDatabaseRealm resourceName=UserDatabase / Host name=localhost appBase=webapps unpackWARs=true autoDeploy=true liveDeploy=true xmlValidation=false xmlNamespaceAware=false /Host /Engine /Service /Server CONTEXT.XML: Context path=/xx docBase=xx debug=5 reloadable=true crossContext=true Resource name=jdbc/xxDB auth=Container type=javax.sql.DataSource maxActive=100 maxIdle=30 maxWait=1 username=user password=pass driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/xx_xx?autoReconnect=true/ /Context WEB.XML: ?xml version=1.0 encoding=UTF-8? web-app xmlns=http://java.sun.com/xml/ns/j2ee; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xsi:schemaLocation=http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd; version=2.4 display-namexx/display-name listener listener-classxxx.ApplicationWatch/listener-class /listener servlet servlet-namehtmlcontent/servlet-name servlet-classxxx.HtmlContentServlet/servlet-class /servlet servlet-mapping servlet-namehtmlcontent/servlet-name url-pattern/htmlcontent.view/url-pattern /servlet-mapping resource-ref descriptionDB Connection/description res-ref-namejdbc/xxDB/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref security-constraint display-nameSecurity Constraint/display-name web-resource-collection web-resource-nameProtected Area/web-resource-name url-pattern/*/url-pattern /web-resource-collection auth-constraint role-namexx/role-name /auth-constraint /security-constraint login-config auth-methodBASIC/auth-method realm-nameProtected Area/realm-name /login-config security-role role-namexx/role-name /security-role /web-app THE WAY I CONNECT TO DB (this is one of the 6-7 methods i have to do stuff on db): private static Connection con = null; private static Connection getConnection() throws Exception { // get context: provides the starting point for resolution of names Context ctx = new InitialContext(); if (ctx == null) { throw new Exception(No Context); } // retrieve datasource DataSource ds = (DataSource) ctx.lookup(java:comp/env/jdbc/xxDB); if (ds == null) { throw new Exception(No Datasource); } // return db connection return ds.getConnection(); } public static void doSomething() { Statement stmt = null; try { // get connection con = getConnection(); if (con == null) { throw new Exception(No Connection); } stmt = con.createStatement(); stmt.executeUpdate(UPDATE yy SET `zz`=0 WHERE `ww`='oo'); } catch (Exception e1) { // } // close resources finally { try { stmt.close(); stmt = null; } catch (SQLException e2) { // } try { con.close(); con = null; } catch (SQLException e3) { // } } } Anybody have a clue of what can be? any help appreciated. -- Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom http://click.libero.it/infostrada - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re:Cannot get a connection, pool exhausted
Now instead of set connection static i just create a new one for each query to perform, so if there are concurrent queries it shouldn't cause any problem: private Connection getConnection() throws Exception { // get context: provides the starting point for resolution of names Context ctx = new InitialContext(); if (ctx == null) { throw new Exception(No Context); } // retrieve datasource DataSource ds = (DataSource) ctx.lookup(java:comp/env/jdbc/xxDB); if (ds == null) { throw new Exception(No Datasource); } // return db connection return ds.getConnection(); } public void doSomething() { Connection con = null; Statement stmt = null; try { // get connection con = getConnection(); if (con == null) { throw new Exception(No Connection); } stmt = con.createStatement(); stmt.executeUpdate(UPDATE yy SET `zz`=0 WHERE `ww`='oo'); } catch (Exception e1) { // } // close resources finally { try { stmt.close(); stmt = null; } catch (Exception e2) { // } try { con.close(); con = null; } catch (Exception e3) { // } } } is there anything else i should change for getting the pool connection to work? Thanks in advance. -- Initial Header --- From : [EMAIL PROTECTED] [EMAIL PROTECTED] To : users users@tomcat.apache.org Cc : Date : Sat, 21 Apr 2007 10:08:21 +0200 Subject : Cannot get a connection, pool exhausted Hello, i'm trying to achieve DBCP with tomcat 5.5.9. I thought to have done things right since the application could connect to db, but after a night that the application was running, in the morning, in logs, i saw a lot of Cannot get a connection, pool exhausted errors. This is my configuration: SERVER.XML: Server port=8005 shutdown=SHUTDOWN Listener className=org.apache.catalina.mbeans.ServerLifecycleListener / Listener className=org.apache.catalina.mbeans.GlobalResourcesLifecycleListener / Listener className=org.apache.catalina.storeconfig.StoreConfigLifecycleListener / GlobalNamingResources Environment name=simpleValue type=java.lang.Integer value=30 / Resource name=UserDatabase auth=Container type=org.apache.catalina.UserDatabase description=User database that can be updated and saved factory=org.apache.catalina.users.MemoryUserDatabaseFactory pathname=conf/tomcat-users.xml / /GlobalNamingResources Service name=Catalina Connector port=8080 maxHttpHeaderSize=8192 maxThreads=150 minSpareThreads=25 maxSpareThreads=75 enableLookups=false redirectPort=8443 acceptCount=100 connectionTimeout=2 disableUploadTimeout=true / Connector port=8009 enableLookups=false redirectPort=8443 protocol=AJP/1.3 / Engine name=Catalina defaultHost=localhost Realm className=org.apache.catalina.realm.UserDatabaseRealm resourceName=UserDatabase / Host name=localhost appBase=webapps unpackWARs=true autoDeploy=true liveDeploy=true xmlValidation=false xmlNamespaceAware=false /Host /Engine /Service /Server CONTEXT.XML: Context path=/xx docBase=xx debug=5 reloadable=true crossContext=true Resource name=jdbc/xxDB auth=Container type=javax.sql.DataSource maxActive=100 maxIdle=30 maxWait=1 username=user password=pass driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/xx_xx?autoReconnect=true/ /Context WEB.XML: ?xml version=1.0 encoding=UTF-8? web-app xmlns=http://java.sun.com/xml/ns/j2ee; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xsi:schemaLocation=http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd; version=2.4 display-namexx/display-name listener listener-classxxx.ApplicationWatch/listener-class /listener servlet servlet-namehtmlcontent/servlet-name servlet-classxxx.HtmlContentServlet/servlet-class /servlet servlet-mapping servlet-namehtmlcontent/servlet-name url-pattern/htmlcontent.view/url-pattern /servlet-mapping resource-ref descriptionDB Connection/description res-ref-namejdbc/xxDB/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref security-constraint display-nameSecurity Constraint/display-name web-resource-collection web-resource-nameProtected Area/web-resource-name url-pattern/*/url-pattern /web-resource-collection auth-constraint role-namexx/role-name /auth-constraint /security-constraint login-config auth-methodBASIC/auth-method realm-nameProtected Area/realm-name /login-config security-role role-namexx/role-name /security-role /web-app THE WAY I CONNECT TO DB (this is one of the 6-7 methods i
Different security constraints for different ip addresses
I want to be able to give non login authorization for a local subnet, but force everybody else to login to a site. Can I do this with combinations of ip-constraint and auth-constraint in web.xml? Something like the following would give access to a private subnet. Could I give access to everybody else by forcing them to login? security-constraint web-resource-collection url-pattern/admin/*/url-pattern /web-resource-collection ip-constraint allow192.168.1.0/24/allow /ip-constraint /security-constraint Thanks. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cannot get a connection, pool exhausted
On 4/21/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: is there anything else i should change for getting the pool connection to work? Thanks in advance. Most of the best practices and common mistakes to avoid are covered here: http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html IMO, especially under: Random Connection Closed Exceptions Also this http://jakarta.apache.org/commons/dbcp/configuration.html provides additional documentation on the various parameters. -Rashmi - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Different security constraints for different ip addresses
Omar Eljumaily wrote: I want to be able to give non login authorization for a local subnet, but force everybody else to login to a site. Can I do this with combinations of ip-constraint and auth-constraint in web.xml? No, since the servlet spec does not define a constraint based on ip-address. Options that would work include: - a filter - separate contexts and a remote address valve Mark - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Session across multiple hosts?
Greetings! Earthling Jeremy, Never tried this before, but I'm going to have a guess because I've seen this question before, and that didn't seem to have much luck... The underlying technology at work is the cookie... so what happens is the browser gets a JsessionId cookie from the server and when it sees the same ID, it automatically resends the required authentication info for the same path... and sub path. Or in layman terms the browser goes... oh its the good guy again... send the password stuff. So if you want to get the browser to treat the 2 domain names the same you have to SOMEHOW set the domain in that JSession cookie. Tomcat will automatically set it to abc.domain.com and def.domain.com. but you need to make it set BOTH machines to .domain.com. Then if Tomcat A authenticates. and say you redirect to Tomcat B the browser will go... Hey its the good guy again because the cookie domain is the same, and in authentication terms its one machine to the browser. Now if you did the authentication programmatically you could just set your own session cookie... because you setting the headers and tomcat doesnt even know you doing authentication but who wants all that hassle, gets very tricky. So here is the real problem as soon as you add all the authentication stuff to web.xml, Tomcat will start doing the cookie thing for you. If you start setting cookies manually and trying to override JSessionID with your own domain name I think you just going to end up with 2 cookies with the same name... Tomcat's make it easy internal session management will fight against you so I think you can forget about doing anything manual once you use the xml configuration. So what I think is that if Tomcat doesnt provide a way to control that session management it cant be done so I looked through the javadocs and I found this.. Valve className=org.apache.catalina.authenticator.SingleSignOn cookieDomain=.domain.com / I'm not sure but I think its what you looking for a way to set the domain name on your servlet's cookie management. ... and single sign on sounds very promising. So good luck BUT remember this is not free advice ;) .. please report back and tell us if it worked, so we can also learn something and this question can be put to rest forever.. thx regards Johnny - Original Message - From: Jeremy Cowgar [EMAIL PROTECTED] To: users@tomcat.apache.org Sent: Friday, April 20, 2007 10:42 PM Subject: Session across multiple hosts? Greetings! I have domain.com and my app uses hosts under that domain, like abc.domain.com, def.domain.com... When the user logs in, the session is valid only on domain.com... How can I make that session also valid under the other hostnames? Thanks, Jeremy - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Session across multiple hosts?
Unfortunately that did not work. The cookie still got set as domain.com, not .domain.com I have in server.xml: Engine name=Catalina defaultHost=localhost Realm className=org.apache.catalina.realm.UserDatabaseRealm resourceName=UserDatabase/ Host name=localhost appBase=webapps unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Valve className=org.apache.catalina.authenticator.SingleSignOn cookieDomain=.localhost/ /Host /Engine Now, this is still in development, thus the localhost, and I've defined many other hostnames in my hosts file, like host1.localhost, host2.localhost, host3.localhost. My app is working great and responding to those correctly, but the cookie is being set as localhost, not .localhost. Jeremy On Apr 21, 2007, at 11:30 AM, Johnny Kewl wrote: So if you want to get the browser to treat the 2 domain names the same you have to SOMEHOW set the domain in that JSession cookie. Tomcat will automatically set it to abc.domain.com and def.domain.com. but you need to make it set BOTH machines to .domain.com. Valve className=org.apache.catalina.authenticator.SingleSignOn cookieDomain=.domain.com / Greetings! I have domain.com and my app uses hosts under that domain, like abc.domain.com, def.domain.com... When the user logs in, the session is valid only on domain.com... How can I make that session also valid under the other hostnames? - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Sticky sessions not changing servers
I've configured mod_jk and have sticky sessions, but every request is going to the exact same Tomcat instance and not the other instance. I've tried setting the loadbalancer method to both Request and Busyness, but they both do the same thing. It works as expected when sticky sessions are disabled. Does this have to do with the fact that my Tomcat WAR isn't doing anything with cookies? Really the WAR in each Tomcat instance only has static pages and images, not really any dynamic stuff going on. Nonetheless, why am I not seeing even split in the jkstatus page of the sticky session requests when I create a new request? For example, if I open up a new browser window and delete browser cookies and make the same request, it still goes to the same instance. How else can I tell my setup that it's a new session that shouldn't remain sticky to the previous Tomcat instance? Thanks a lot. -- View this message in context: http://www.nabble.com/Sticky-sessions-not-changing-servers-tf3624620.html#a10121415 Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Session across multiple hosts?
I had another look at this and I think this has to be the only way... short of writing the authentication code ourselves. For it to work you must have login-config security-constraint stuff in you web.xml file ie if the page is not protected, its not going to start working... and it will only start working when the user logs in to some page. Then in every hosts section we do this Host name=test1.localhost.com appBase=webapps unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Valve className=org.apache.catalina.authenticator.SingleSignOn cookieDomain=.gangbang.com/ /Host Host name=test2.localhost.com appBase=webapps unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Valve className=org.apache.catalina.authenticator.SingleSignOn cookieDomain=.gangbang.com/ /Host So... as soon as someone logs in to a protected page only then should you a see a cookie in the header being set to .gangbang.com And to test you can set 127.0.0.1 test1.localhost.com 127.0.0.1 test2.localhost.com in the computers hosts file... easier than trying to set up a dns to test Then log in to test1.localhost.com page and swap it to test2.localhost.com and see if the user has to relog in. So as soon as a user logs in you should see a cookie in the header whose domain name is being set as .gangbang.com but only when they log in. And because the user has the same role name the same session ID should be used and thus the browser treats all the webapps as one. I dont think it really matters what the cookieDomain is set to as long as its the same for all the host names you using... it will be enough to trick the browser... Of course what may snooker us in the end is IE's security might complain that hostname being set in cookie is not the same as actual host name... but then you know its working and can change gangbang to .domain.com This HAS to work. if it doesnt it means we have to write the code, and not use tomcats authentication it must work or its going to be max work. Wish the documentation explained the actual mechanism a little better but I think we onto the right idea... Have fun. - Original Message - From: Jeremy Cowgar [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Saturday, April 21, 2007 5:50 PM Subject: Re: Session across multiple hosts? Unfortunately that did not work. The cookie still got set as domain.com, not .domain.com I have in server.xml: Engine name=Catalina defaultHost=localhost Realm className=org.apache.catalina.realm.UserDatabaseRealm resourceName=UserDatabase/ Host name=localhost appBase=webapps unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Valve className=org.apache.catalina.authenticator.SingleSignOn cookieDomain=.localhost/ /Host /Engine Now, this is still in development, thus the localhost, and I've defined many other hostnames in my hosts file, like host1.localhost, host2.localhost, host3.localhost. My app is working great and responding to those correctly, but the cookie is being set as localhost, not .localhost. Jeremy On Apr 21, 2007, at 11:30 AM, Johnny Kewl wrote: So if you want to get the browser to treat the 2 domain names the same you have to SOMEHOW set the domain in that JSession cookie. Tomcat will automatically set it to abc.domain.com and def.domain.com. but you need to make it set BOTH machines to .domain.com. Valve className=org.apache.catalina.authenticator.SingleSignOn cookieDomain=.domain.com / Greetings! I have domain.com and my app uses hosts under that domain, like abc.domain.com, def.domain.com... When the user logs in, the session is valid only on domain.com... How can I make that session also valid under the other hostnames? - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]