hi, thanks for the mail, i tried this but the problem still persists, i added the context.xml file in META-INF and the database information was not being picked from there. Also i added the connect-timeout parameter in my.cnf file in the mysqld section, but still the the timeout was after 8 hours of inactivity.
I will appreciate if one can tell me exactly what to do, pl consider me a newbie and will appreciate if the instructions be given. thanks abhishek On Tue, Mar 1, 2011 at 3:26 PM, Maurizio Cucchiara < maurizio.cucchi...@gmail.com> wrote: > I struggled with this issue for a long period, at the end I reached a > good point: I started using database connection pools [1]. > Actually you should wait until the mysql connection dies (it should be > after 8 hours of db inactivity ), but you could change the > connect-timeout=seconds [2] in order to achieve the before mentioned > scenario. > > [1] http://commons.apache.org/dbcp/ > [2] http://dev.mysql.com/doc/refman/5.5/en/mysql-options.html > > > Here my context.xml is: > > <Context > override="true" > reloadable="false" > unpackWARs="true" autoDeploy="true" > liveDeploy="false" allowLinking="true"> > <!-- > maxActive=10 > Don't set this any higher than max_connections on your > MySQL server, usually this should be a 10 or a few 10's > of connections, not hundreds or thousands > --> > <!-- > maxIdle=5 > You don't want to many idle connections hanging around > if you can avoid it, only enough to soak up a spike in > the load > --> > <!-- > validationQuery=select 1 > Don't use autoReconnect=true, it's going away eventually > and it's a crutch for older connection pools that couldn't > test connections. You need to decide whether your application > is supposed to deal with SQLExceptions (hint, it should), and > how much of a performance penalty you're willing to pay > to ensure 'freshness' of the connection > --> > > <!-- > testOnBorrow=true > The most conservative approach is to test connections > before they're given to your application. For most applications > this is okay, the query used above is very small and takes > no real server resources to process, other than the time used > to traverse the network. > > If you have a high-load application you'll need to rely on > something else. > --> > <!-- > testWhileIdle=true > Otherwise, or in addition to testOnBorrow, you can test > while connections are sitting idle > --> > <!-- > timeBetweenEvictionRunsMillis=10000 > You have to set this value, otherwise even though > you've asked connections to be tested while idle, > the idle evicter thread will never run > --> > <!-- > minEvictableIdleTimeMillis=60000 > Don't allow connections to hang out idle too long, > never longer than what wait_timeout is set to on the > server...A few minutes or even fraction of a minute > is sometimes okay here, it depends on your application > and how much spikey load it will see > --> > <!-- > maxWait > Maximum time to wait for a dB connection to become available > in ms, in this example 10 seconds. An Exception is thrown if > this timeout is exceeded. Set to -1 to wait indefinitely. > --> > <!-- > removeAbandoned=true > > A database connection pool creates and manages a pool of > connections to a database. Recycling and reusing already > existing connections to a dB is more efficient than opening a > new connection. > > There is one problem with connection pooling. A web > application has to explicetely close ResultSet's, Statement's, > and Connection's. > Failure of a web application to close these resources can > result in them never being available again for reuse, > a db connection pool "leak". This can eventually result in > your web application db connections failing if there > are no more available connections. > > There is a solution to this problem. The Jakarta-Commons DBCP > can be configured to track and recover these > abandoned dB connections. Not only can it recover them, but > also generate a stack trace for the code which > opened these resources and never closed them. > > --> > <!-- > removeAbandonedTimeout="60" > Use the removeAbandonedTimeout attribute to set the number of > seconds a dB connection has been idle before it > is considered abandoned. > --> > <!-- > logAbandoned=true > The logAbandoned attribute can be set to true if you want DBCP > to log a stack trace of the code which abandoned > the dB connection resources. > --> > <Resource > type="javax.sql.DataSource" > name="jdbc/${CONTEXT_NAME}" > password="PASSWORD" > driverClassName="org.gjt.mm.mysql.Driver" > username="${USERNAME}" > > url="jdbc:mysql://localhost/${DB_NAME}?zeroDateTimeBehavior=convertToNull" > auth="Container" > factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" > maxActive="20" > maxIdle="5" > validationQuery="select 1" > testOnBorrow="true" > testWhileIdle="true" > timeBetweenEvictionRunsMillis="10000" > minEvictableIdleTimeMillis="60000" > maxWait="5000" > removeAbandoned="true" > removeAbandonedTimeout="60" > logAbandoned="true" > /> > </Context> > > > On 1 March 2011 07:09, abhishek jain <abhishek.netj...@gmail.com> wrote: > > hi, > > this didnt solved, i created a file c3po.properties with the mentioned > > property and it didnt solved. > > also i have to wait a day for the error message, is there a way where i > can > > reduce this time during test? > > > > > > thanks > > abhi > > > > On Sat, Feb 26, 2011 at 12:32 AM, Burton Rhodes <burtonrho...@gmail.com > >wrote: > > > >> I recall having a similiar issue when moving to MySQL from MSSQL. I > >> solved it by adding c3po.properties file to the classpath with the > >> text below. It kept the connection alive with the database. > >> > >> # This property corresponds to the query run defined by the > >> "hibernate.c3p0.idle_test_period" value > >> c3p0.preferredTestQuery = SELECT 1; > >> > >> On Fri, Feb 25, 2011 at 12:53 AM, Jerson John <jer...@cprvision.com> > >> wrote: > >> > Hi, > >> > > >> > Yup I faced this problem before and flush to Hibernate group.They > have > >> > suggested me some solution based on my mapping xml fle....Why don't u > >> send > >> > me that mapping xml and let me compare with mine.....Actually Even > though > >> it > >> > look like Server error,its more to do with hibernate ....Please feel > free > >> to > >> > currect me if my assumption is wrong > >> > > >> > Many Thanks and Regards, > >> > > >> > Jerson > >> > > >> > > >> > -----Original Message----- > >> > From: abhishek jain [mailto:abhishek.netj...@gmail.com] > >> > Sent: Friday, February 25, 2011 2:31 PM > >> > To: Struts Users Mailing List > >> > Subject: Exception in hibernate3 > >> > > >> > hi, > >> > I am not sure if i am ringing the correct list, but i am sure people > here > >> > must have encountered this problem. I am new to hibernate and when i > ran > >> the > >> > code on server it was fine , strangely next day it keep on giving this > >> error > >> > till i restart tomcat. > >> > > >> > The last packet successfully received from the server was 54,880,316 > >> > milliseconds ago. The last packet sent successfully to the server was > >> > 54,880,317 milliseconds ago. is longer than the server configured > value > >> of > >> > 'wait_timeout'. You should consider either expiring and/or testing > >> > connection validity before use in your application, increasing the > server > >> > configured values for client timeouts, or using the Connector/J > >> connection > >> > property 'autoReconnect=true' to avoid this problem. > >> > > >> > I have searched a lot on net and added the following properties on > >> > hibernate.cfg.xml, as people there were suggesting this,but of no use. > >> > <!-- Sessions and transactions --> > >> > <!-- Use the C3P0 connection pool provider --> > >> > <property name="hibernate.c3p0.min_size">5</property> > >> > <property name="hibernate.c3p0.max_size">20</property> > >> > <property name="hibernate.c3p0.timeout">300</property> > >> > <property name="hibernate.c3p0.max_statements">50</property> > >> > <property name="hibernate.c3p0.idle_test_period">3000</property> > >> > <property name="current_session_context_class">thread</property> > >> > > >> > > >> > > >> > Pl. help me. > >> > I have used hibernate3 with myeclipse as the development environment, > and > >> am > >> > using mysql 5.x and centos (Linux) with Tomcat 5.x > >> > -- > >> > > > > > > -- > Maurizio Cucchiara > >