Re: connection pooling
java code: Context ctx = (Context) init.lookup(xx); server.xml: ResourceParams name=xx web.xml: resource-ref res-ref-namexx/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref The entries I've labelled 'xx' should all be the same. John Thompson |-+ | | Eric Wulff | | | [EMAIL PROTECTED]| | | | | || | | 07/10/2004 10:37 | | | AM | | | Please respond to| | | Tomcat Users| | | List| | || |-+ --| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: connection pooling | --| I have gone over some of the tomcat docs and googled errors but there is SO much information covering JNDI, connection pooling, and Datasources. Can someone review the info below and consult or point me in the right direction? Although I feel I'm missing something obvious, I can't find out what's wrong with my set-up. thx Eric System: Tomcat 5 on Fedora Core 2 connecting to a db on an Informix Dynamic Server 9.4 on Windows Server -I am able to connect to my db via typical JDBC DriverManager.getConnection(). This leads me to believe that my informix jdbc driver is in the correct place... CATALINA_HOME/common/lib -I have a Context set up in my server.xml per examples in a text tutorial I'm referencing Below listed... -errors -web.xml -server.xml Context (minus connection actual values) -.java exception/errors: -Exception: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' SQL state: null Error code: 0 -stack trace reveals this, but I can't see why since I have the driver in the correct directory... java.sql.SQLException: No suitable driver at java.sql.DriverManager.getDriver(DriverManager.java:243) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773) web.xml: ?xml version=1.0 encoding=ISO-8859-1? !DOCTYPE web-app PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN http://java.sun.com/dtd/web-app_2_3.dtd; web-app servlet servlet-nameTest Connection Pooling/servlet-name servlet-classTestConnectionPooling/servlet-class /servlet servlet-mapping servlet-nameTest Connection Pooling/servlet-name url-pattern/testConnectionPooling/url-pattern /servlet-mapping resource-ref res-ref-namejdbc/test_connect/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref /web-app server.xml Context: Context path=/testConnectionPooling docBase=testConnectionPooling debug=0 reloadable=true ResourceParams name=jdbc/test_connect parameter nameusername/name valueinformix/value /parameter parameter namepassword/name valueinformix/value /parameter parameter namedriverClassName/name valuecom.informix.jdbc.IfxDriver/value /parameter parameter nameurl/name valuejdbc:informix-sqli://url:port/dbName:INFORMIXSERVER=serverName/value /parameter /ResourceParams /Context .java: import java.io.*; import java.sql.*; // -Must import javax.naming use JNDI which is required to implement data // resource references and hence connection pooling. import javax.naming.*; import javax.sql.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class TestConnectionPooling extends HttpServlet { private DataSource dataSource; public void init(ServletConfig config) throws ServletException { try { Context init = new InitialContext(); // don't know what the 'java:comp/env' refers to Context ctx = (Context) init.lookup(java:comp/env); // I know jdbc/conversion must match the web.xml res-ref-name of the web.xml but don't know what the path really refers to dataSource = (DataSource) ctx.lookup(jdbc/test_connect); } catch (NamingException ex) { throw new ServletException(Cannot retrieve java:comp/env/jdbc/test_connect,ex); } } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Re: connection pooling
Please ignore my last post - it's wrong. (Answered before verifying). John Thompson |-+ | | Eric Wulff | | | [EMAIL PROTECTED]| | | | | || | | 07/10/2004 10:37 | | | AM | | | Please respond to| | | Tomcat Users| | | List| | || |-+ --| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: connection pooling | --| I have gone over some of the tomcat docs and googled errors but there is SO much information covering JNDI, connection pooling, and Datasources. Can someone review the info below and consult or point me in the right direction? Although I feel I'm missing something obvious, I can't find out what's wrong with my set-up. thx Eric System: Tomcat 5 on Fedora Core 2 connecting to a db on an Informix Dynamic Server 9.4 on Windows Server -I am able to connect to my db via typical JDBC DriverManager.getConnection(). This leads me to believe that my informix jdbc driver is in the correct place... CATALINA_HOME/common/lib -I have a Context set up in my server.xml per examples in a text tutorial I'm referencing Below listed... -errors -web.xml -server.xml Context (minus connection actual values) -.java exception/errors: -Exception: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' SQL state: null Error code: 0 -stack trace reveals this, but I can't see why since I have the driver in the correct directory... java.sql.SQLException: No suitable driver at java.sql.DriverManager.getDriver(DriverManager.java:243) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773) web.xml: ?xml version=1.0 encoding=ISO-8859-1? !DOCTYPE web-app PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN http://java.sun.com/dtd/web-app_2_3.dtd; web-app servlet servlet-nameTest Connection Pooling/servlet-name servlet-classTestConnectionPooling/servlet-class /servlet servlet-mapping servlet-nameTest Connection Pooling/servlet-name url-pattern/testConnectionPooling/url-pattern /servlet-mapping resource-ref res-ref-namejdbc/test_connect/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref /web-app server.xml Context: Context path=/testConnectionPooling docBase=testConnectionPooling debug=0 reloadable=true ResourceParams name=jdbc/test_connect parameter nameusername/name valueinformix/value /parameter parameter namepassword/name valueinformix/value /parameter parameter namedriverClassName/name valuecom.informix.jdbc.IfxDriver/value /parameter parameter nameurl/name valuejdbc:informix-sqli://url:port/dbName:INFORMIXSERVER=serverName/value /parameter /ResourceParams /Context .java: import java.io.*; import java.sql.*; // -Must import javax.naming use JNDI which is required to implement data // resource references and hence connection pooling. import javax.naming.*; import javax.sql.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class TestConnectionPooling extends HttpServlet { private DataSource dataSource; public void init(ServletConfig config) throws ServletException { try { Context init = new InitialContext(); // don't know what the 'java:comp/env' refers to Context ctx = (Context) init.lookup(java:comp/env); // I know jdbc/conversion must match the web.xml res-ref-name of the web.xml but don't know what the path really refers to dataSource = (DataSource) ctx.lookup(jdbc/test_connect); } catch (NamingException ex) { throw new ServletException(Cannot retrieve java:comp/env/jdbc/test_connect,ex); } } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/html); PrintWriter out = response.getWriter(); Connection connection = null; out.println (HTMLHEADTITLETest Connection Pooling/TITLE/HEADBODY); out.println(H1Customer Name Query/H1); try {
Re: connection pooling
parameter nameurl/name valuejdbc:informix-sqli://url:port/dbName:INFORMIXSERVER=serverName/value /parameter Is that litterally what you have in your server.xml? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: connection pooling
Is there a x.xml file in (TOMCAT_HOME)/conf/Catalina/localhost, where xx is the context name? (this is an independent context configuration that may have been created independently when you first deployed your application on Tomcat). If so, either delete it, or move your data source definition out of server.xml and into this file (remove the entire context from server.xml). - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tomcat becoming almost completely non-responsive
The most likely reason for your connections not being re-used is that your java code isn't explicitly closing connections, statements and result sets after use. If visiting all your code is too onerous a task, you could add the following parameters to your data-source configuration: parameter nameremoveAbandoned/name valuetrue/value /parameter parameter nameremoveAbandonedTimeout/name value60/value /parameter The effect of the above is to mark any data-pool connection as re-usable after 60 seconds of inactivity. You can add the following to log abandonned connection activity: parameter namelogAbandoned/name valuetrue/value /parameter John Thompson |-+ | | Kaleb Pederson | | | [EMAIL PROTECTED]| | | wu.edu | | || | | 02/10/2004 10:07 | | | AM | | | Please respond to| | | Tomcat Users| | | List| | || |-+ --| | | | To: Tomcat Users List [EMAIL PROTECTED] | | cc: | | Subject: Tomcat becoming almost completely non-responsive | --| Hello, I have an interesting problem. After a while, tomcat (5.0.27) becomes almost completely non-responsive. If I telnet in to port 8009 (I'm using apache and mod_jk2), I get no response, at least not within the default timeout. If a browse to a page, I will generally, after about 4-5 minutes, see a page returned. To narrow down the slowness, I generated a full thread dump, and found the following information: [ see attachment for more info] Total threads: 180 executeQuery: 2 // executing a db query validateConnection: 0 // trying to validate their connection validateObect: 48 // in commons.dbcp.PoolableConnectionFactory.validateObject socketAccept: 3 // accepting a socket socketRead0: 10 // reading a socket ReferenceQueue: 1 ThreadPool$MonitorRunnable: 2 borrowObject and Object.wait: 85 // trying to get an object from the pool Object.wait: 20 // threads just waiting around Remaining: 9 // misc. threads My database connection is setup so that I have 50 allowed connections, which matches my 48 in validateObject and 2 executing queries. However, when I query the database status, I see 2 active threads and the rest are 'sleeping', just waiting around, as they would be if the connection pool hadn't released them yet. So, why would there be 48 connections that seemed locked and weren't querying the DB? And then the other 85 that were seemingly waiting on the 45? Any ideas what might be going on? The DB is ready? I have log abandoned turned and an haven't seen a problem yet. If the load drops sufficiently on the server, everything eventually returns back to normal, otherwise it takes 5-10 minutes to get a response from the server. I have attached an abbreviated form of the thread dump which should provide all the critical information and can provide as much other information as is necessary. Thanks for the help. *All* suggestions welcome ;) --Kaleb - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: method level synchronization doesn't work
Is your primary key generated automatically? If so, the combined insert/query is: String stmt=INSERT INTO SOMEFILE (FLD1,FLD2,FLD3) VALUES(?,?,?); PreparedStatement sql = conn.prepareStatement(stmt,Statement.RETURN_GENERATED_KEYS); sql.setInt(1,fld1); sql.setInt(2,fld2); sql.setInt(3,fld3); sql.execute(); ResultSet rs = sql.getGeneratedKeys(); if (rs.next()) { // get generated key int key=rs.getInt(1); } |-+ | | Mike Curwen| | | [EMAIL PROTECTED]| | | ndless.com | | || | | 01/10/2004 02:14 PM | | | Please respond to| | | Tomcat Users List | | || |-+ --| | | | To: 'Tomcat Users List' [EMAIL PROTECTED] | | cc: | | Subject: RE: method level synchronization doesn't work | --| Ok, since it's been brought forward... how do you update and retrieve all in one query? This is for: I need a new primary key, and I need it to be thread safe. something that would run on mysql? unless you can get this magic query, it's not quite as simple as let the databse handle it, is it? -Original Message- From: Peter Lin [mailto:[EMAIL PROTECTED] Sent: Thursday, September 30, 2004 7:42 PM To: Tomcat Users List; [EMAIL PROTECTED] Subject: Re: method level synchronization doesn't work that would be the easiest way. but you made it too easy, I thought people are suppose to suffer and stumble :) peter On Thu, 30 Sep 2004 17:46:51 -0400, Frank W. Zammetti [EMAIL PROTECTED] wrote: Why not just let SQL do the update? Do the following: update my_table set counter_field = counter_field + 1 (where clause here if needed) (off the top of my head, my syntax might be off) In other words, why not let the database handle the concurrency issue? That's kind of what they're there for (partly anyway). - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Tomcat 5.0 contexts
You need to specify swallowOutput=true on your context tag to get a separate Tomcat log, eg: Context docBase=/webapps/printerparts path=/printerparts reloadable=true swallowOutput=true Regards, John [EMAIL PROTECTED] Ph (09) 372-5010 |-+--- | | Luc Foisy | | | [EMAIL PROTECTED]| | | -magic.com | | | | | | 25/09/2004 02:37 AM | | | Please respond to | | | Tomcat Users List | | | | |-+--- --| | | | To: Tomcat Users List [EMAIL PROTECTED] | | cc: | | Subject: RE: Tomcat 5.0 contexts | --| Thank you. I did get my context to load from Catalina/localhost/qbs.xml INFO: Processing Context configuration file URL file:/home/tomcat/conf/Catalina/localhost/qbs.xml It does not seem to be honoring the logger, even when I use an absolute directory. If it matters, Using RedHat 9.0, jdk 1.4.2_05, tomcat 5.0.28. I have never used one of those logging mechanisms, I have only used the tomcat logger. I will look at those others, since I can't seem to get the Tomcat logger to work at all, which is odd considering the default logger (in server.xml) for all contexts on host seems to be working fine, as well as the logger for the admin context -Original Message- From: Shapira, Yoav [mailto:[EMAIL PROTECTED] Sent: Friday, September 24, 2004 9:29 AM To: Tomcat Users List Subject: RE: Tomcat 5.0 contexts Hi, Is something wrong with my logger declaration? It does not seem to be creating the logs that I specified. Ahh, I didn't even look at that. I think it looks fine. Try specifying a known absolute directory rather than a relative one (logs) to see if that makes a difference. Heads-up -- don't spend much time on Logger configuration unless you have to. If you're already using log4j, JDK 1.4 logging, or commons-logging, stick to those and don't use a Tomcat Logger. If you're not already using one of these packages, consider starting ;) Yoav - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]