ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Bauld <bau...@cpsc.ucalgary.ca>
Subject Re: Connection closing after timeout on tomcat
Date Fri, 25 Aug 2006 19:51:18 GMT
Thanks, I added this to my <sqlMapConfig> I had no idea this existed... 
I must have read over it plenty of times but never put them together. 
Now I wait and see if this solves the problem.

    <transactionManager type="JDBC" >
        <dataSource type="SIMPLE">
            <property name="JDBC.Driver" value="${driver}"/>
            <property name="JDBC.ConnectionURL" value="${url}"/>
            <property name="JDBC.Username" value="${username}"/>
            <property name="JDBC.Password" value="${password}"/>
            <property name="Pool.TimeToWait" value="500"/>
            <property name="Pool.PingQuery" value="SELECT 1"/>
            <property name="Pool.PingEnabled" value="true"/>
            <property name="Pool.PingConnectionsOlderThan" value="3600000"/>
            <property name="Pool.PingConnectionsNotUsedFor" 
value="3600000"/>
        </dataSource>
    </transactionManager>


Poitras Christian wrote:
> Try adding a ping query to your sql-map-config. It will detect closed
> connection and create a new one.
>
> Christian 
>
> -----Original Message-----
> From: Eric Bauld [mailto:baulde@cpsc.ucalgary.ca] 
> Sent: Friday, 25 August 2006 15:19
> To: user-java@ibatis.apache.org
> Subject: Re: Connection closing after timeout on tomcat
>
> Unsure about using DBCP so probably not. I am creating a new instance of
> a SqlMapClient each time a servlet is run.
>
> iBatis 2.1.7
> apache-tomcat 5.5.7
> mysql 4.1.11
>
> The servlets are accessed from a php script and the output is passed
> through apache as a excell file. Its not used that often.
>
> Each servlet executes this
> SQLMapper.setIBATIS( sysprops.getProperty( "ibatis" ) );
>
> And everything that uses ibatis accesses the SqlMapClient does so via
> SQLMapper.getSqlMapInstance()
>
>
> And SQLMapper is as follows
>
>
> package rp.broker;
>
> import java.io.Reader;
> import java.sql.SQLException;
>
>
> import com.ibatis.common.resources.Resources;
> import com.ibatis.sqlmap.client.SqlMapClient;
> import com.ibatis.sqlmap.client.SqlMapClientBuilder;
>
>
>
> public class SQLMapper {
>     private static SqlMapClient sqlMap;
>     private static String iBATIS;
>   
>     private static void setup(){
>         try {
>            
>             String resource = SQLMapper.getIBATIS();
>             Reader reader = Resources.getResourceAsReader(resource);
>             sqlMap = null;
>             SQLMapper.sqlMap =
> SqlMapClientBuilder.buildSqlMapClient(reader);
>         } catch (Exception e) {
>             //An error at this point is unrecoverable, so this should
> die
>             e.printStackTrace();
>             throw new RuntimeException(
>                 "Error initializing SQLMapper class.Cause : " +e);
>         }
>     }
>    
>     public static SqlMapClient getSqlMapInstance() throws SQLException {
>
>         return sqlMap;
>     }
>    
>     public static void close(){
>     }
>    
>     public static void setIBATIS(String iBATIS) {
>         SQLMapper.iBATIS = iBATIS;
>         setup();
>     }
>     public static String getIBATIS() {
>         return iBATIS;
>     }
> }
>
> Kris Schneider wrote:
>   
>> On 8/25/06, Eric Bauld <baulde@cpsc.ucalgary.ca> wrote:
>>     
>>> Im having a heck of a time finding the right way to fix this.
>>> I have a servlet on a tomcat server, it uses ibatis. It works great 
>>> as long as it is being used but when it sits overnight, the 
>>> connection times out and the next person to use it will get an error.
>>>       
>
>   
>>> But then it will work for every request thereafter.
>>> I get this exception after it has been sitting.
>>>
>>> java.sql.SQLException: No operations allowed after connection closed
>>>
>>> Anyone know of a way to test this to see if the connection has closed
>>>       
> ?
>   
>> If you're using DBCP for your connection pooling, see this:
>>
>> http://jakarta.apache.org/commons/dbcp/configuration.html
>>
>> Specifically the testOnBorrow and validationQuery params.
>>
>>     
>>> I could just put a bogus query + error catch to "wake up" the 
>>> connection, but its not a very proper fix.
>>>
>>>  - Eric
>>>       
>
>
>   


Mime
View raw message