You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Yevgen Krapiva <yk...@gmail.com> on 2010/07/06 09:05:30 UTC

java.lang.IllegalStateException: Timer already cancelled

Hi guys.

I have a servlet that uses connection pool with the use of MySQL driver.
When I start or reload Tomcat the application works fine, then if I
redeploy my application it cannot get a connection from a DataSource object.
The following exception is thrown:

java.lang.IllegalStateException: Timer already cancelled.

java.util.Timer.sched(Timer.java:354)
java.util.Timer.schedule(Timer.java:222)
org.apache.tomcat.dbcp.pool.impl.EvictionTimer.schedule(EvictionTimer.java:64)
org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.startEvictor(GenericObjectPool.java:1647)
org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.setTimeBetweenEvictionRunsMillis(GenericObjectPool.java:843)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1173)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
basis.onlineorder.commons.dao.UserDAOJdbcImpl.getUsers(UserDAOJdbcImpl.java:133)
org.apache.jsp.users_jsp.getUsersList(users_jsp.java:31)
org.apache.jsp.users_jsp._jspService(users_jsp.java:164)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

I have not found anything I can do with this on the internet. Perhaps I've
found that I might have a relation to
timeBetweenEvictionRunsMillis parameter ( in <Resource> configuration
section ).

I don't know if it is important, here is my configuration in context.xml
file:

<Resource name="jdbc/onlineorder"
auth="Container"
type="javax.sql.DataSource"
username="user"
password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/mydb?useUnicode=true&amp;characterEncoding=utf8"
maxActive="10"
maxIdle="5"
testOnBorrow="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="10000"
minEvictableIdleTimeMillis="60000"
/>

Did anyone face with this problem ?

Re: java.lang.IllegalStateException: Timer already cancelled

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/7/6 Yevgen Krapiva <yk...@gmail.com>:
> Thanks, I'll do that.
> What about "minEvictableIdleTimeMillis" ? Just delete it ?
>

You can delete it. It is the timeBetweenEvictionRunsMillis attribute
that controls whether the Evictor will be enabled. The other
attributes make no difference.

http://commons.apache.org/dbcp/configuration.html

Best regards,
Konstantin Kolinko

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


Re: java.lang.IllegalStateException: Timer already cancelled

Posted by Yevgen Krapiva <yk...@gmail.com>.
Thanks, I'll do that.
What about "minEvictableIdleTimeMillis" ? Just delete it ?

2010/7/6 Konstantin Kolinko <kn...@gmail.com>

> 2010/7/6 Yevgen Krapiva <yk...@gmail.com>:
> > Hi guys.
> >
> > I have a servlet that uses connection pool with the use of MySQL driver.
> > When I start or reload Tomcat the application works fine, then if I
> > redeploy my application it cannot get a connection from a DataSource
> object.
>
> Do not use eviction in DBCP, because it causes a memory leak.
>
> See
> https://issues.apache.org/bugzilla/show_bug.cgi?id=48971
> https://issues.apache.org/jira/browse/POOL-161
>
> Remove "timeBetweenEvictionRunsMillis" attribute, or set it to "-1".
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: java.lang.IllegalStateException: Timer already cancelled

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/7/6 Yevgen Krapiva <yk...@gmail.com>:
> Hi guys.
>
> I have a servlet that uses connection pool with the use of MySQL driver.
> When I start or reload Tomcat the application works fine, then if I
> redeploy my application it cannot get a connection from a DataSource object.

Do not use eviction in DBCP, because it causes a memory leak.

See
https://issues.apache.org/bugzilla/show_bug.cgi?id=48971
https://issues.apache.org/jira/browse/POOL-161

Remove "timeBetweenEvictionRunsMillis" attribute, or set it to "-1".

Best regards,
Konstantin Kolinko

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


Re: java.lang.IllegalStateException: Timer already cancelled

Posted by Pid <pi...@pidster.com>.
On 06/07/2010 11:34, Yevgen Krapiva wrote:
> I've tried today the latest driver available - 5.1.13. 
> I've places the driver to %CATALINA_HOME%/lib.
> 
> I also tried to move it to WEB-INF\lib, but it is appeared that Tomcat
> (I'm using 6.0.26) doesn't see
> it when trying to create connection from a DataSource. He says
> ClassNotFoundException.

You'll need to define the DataSource (and anything else that depends on
it, like a Realm*) in myapp/META-INF/context.xml if you place the driver
jar in WEB-INF/lib.  Global resources defined in server.xml can't use
jars located in a web app ClassLoader.

> I don't know why but when I test it using Class.forName() - it exists.
> I think Tomcat doesn't use servlet classloader.
> 
> So, returning to the problem , I think the problem is with
> org.apache.tomcat.dbcp.pool.impl.EvictionTimer class, because
> it is actually throws exception.

It is indeed.  I was looking at a similar problem in the MySQL driver
and completely failed to read the stacktrace properly, my apologies.

The o.a.tomcat.dbcp classes are a repackaged version of commons-dbcp &
commons-pool so we'll have to look in the source there.

 http://svn.apache.org/repos/asf/commons/proper/dbcp/
 http://svn.apache.org/repos/asf/commons/proper/pool/

And:

 http://svn.apache.org/repos/asf/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/EvictionTimer.java


So, is your application the only application running on the server?


p


* DataSourceRealms defined with DataSources in the Context definition
need localDataSource=true setting as per:

 http://tomcat.apache.org/tomcat-6.0-doc/config/realm.html

> 2010/7/6 Pid <pid@pidster.com <ma...@pidster.com>>
> 
>     On 06/07/2010 08:22, Pid wrote:
>     > On 06/07/2010 08:05, Yevgen Krapiva wrote:
>     >> Hi guys.
>     >>
>     >> I have a servlet that uses connection pool with the use of MySQL
>     driver.
>     >> When I start or reload Tomcat the application works fine, then if I
>     >> redeploy my application it cannot get a connection from a
>     DataSource object.
>     >> The following exception is thrown:
>     >>
>     >> java.lang.IllegalStateException: Timer already cancelled.
>     >>
>     >> java.util.Timer.sched(Timer.java:354)
>     >> java.util.Timer.schedule(Timer.java:222)
>     >>
>     org.apache.tomcat.dbcp.pool.impl.EvictionTimer.schedule(EvictionTimer.java:64)
>     >>
>     org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.startEvictor(GenericObjectPool.java:1647)
>     >>
>     org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.setTimeBetweenEvictionRunsMillis(GenericObjectPool.java:843)
>     >>
>     org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1173)
>     >>
>     org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
>     >>
>     basis.onlineorder.commons.dao.UserDAOJdbcImpl.getUsers(UserDAOJdbcImpl.java:133)
>     >> org.apache.jsp.users_jsp.getUsersList(users_jsp.java:31)
>     >> org.apache.jsp.users_jsp._jspService(users_jsp.java:164)
>     >> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>     >> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>     >>
>     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
>     >>
>     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
>     >> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
>     >> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>     >>
>     >> I have not found anything I can do with this on the internet.
>     Perhaps I've
>     >> found that I might have a relation to
>     >> timeBetweenEvictionRunsMillis parameter ( in <Resource> configuration
>     >> section ).
>     >>
>     >> I don't know if it is important, here is my configuration in
>     context.xml
>     >> file:
>     >>
>     >> <Resource name="jdbc/onlineorder"
>     >> auth="Container"
>     >> type="javax.sql.DataSource"
>     >> username="user"
>     >> password="password"
>     >> driverClassName="com.mysql.jdbc.Driver"
>     >>
>     url="jdbc:mysql://localhost/mydb?useUnicode=true&amp;characterEncoding=utf8"
>     >> maxActive="10"
>     >> maxIdle="5"
>     >> testOnBorrow="true"
>     >> testWhileIdle="true"
>     >> timeBetweenEvictionRunsMillis="10000"
>     >> minEvictableIdleTimeMillis="60000"
>     >> />
>     >>
>     >> Did anyone face with this problem ?
>     >
>     > Exactly which version of the MySQL driver are you using?
>     >
>     > This is a side-effect of the memory leak prevention in Tomcat 6.0.20+
>     > which aims to stop Timers that haven't been properly shutdown.
> 
>     Correction, Timer Thread termination was introduced in 6.0.24.
>     It's optional from 6.0.27 with the clearReferencesStopTimerThreads flag.
> 
>     You might consider filing a bug with MySQL requesting that they check
>     that the Timer is actually running.
> 
> 
>     p



Re: java.lang.IllegalStateException: Timer already cancelled

Posted by Yevgen Krapiva <yk...@gmail.com>.
I've tried today the latest driver available - 5.1.13.
I've places the driver to %CATALINA_HOME%/lib.

I also tried to move it to WEB-INF\lib, but it is appeared that Tomcat (I'm
using 6.0.26) doesn't see
it when trying to create connection from a DataSource. He says
ClassNotFoundException.
I don't know why but when I test it using Class.forName() - it exists.
I think Tomcat doesn't use servlet classloader.

So, returning to the problem , I think the problem is with
org.apache.tomcat.dbcp.pool.impl.EvictionTimer class, because
it is actually throws exception.


2010/7/6 Pid <pi...@pidster.com>

> On 06/07/2010 08:22, Pid wrote:
> > On 06/07/2010 08:05, Yevgen Krapiva wrote:
> >> Hi guys.
> >>
> >> I have a servlet that uses connection pool with the use of MySQL driver.
> >> When I start or reload Tomcat the application works fine, then if I
> >> redeploy my application it cannot get a connection from a DataSource
> object.
> >> The following exception is thrown:
> >>
> >> java.lang.IllegalStateException: Timer already cancelled.
> >>
> >> java.util.Timer.sched(Timer.java:354)
> >> java.util.Timer.schedule(Timer.java:222)
> >>
> org.apache.tomcat.dbcp.pool.impl.EvictionTimer.schedule(EvictionTimer.java:64)
> >>
> org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.startEvictor(GenericObjectPool.java:1647)
> >>
> org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.setTimeBetweenEvictionRunsMillis(GenericObjectPool.java:843)
> >>
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1173)
> >>
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
> >>
> basis.onlineorder.commons.dao.UserDAOJdbcImpl.getUsers(UserDAOJdbcImpl.java:133)
> >> org.apache.jsp.users_jsp.getUsersList(users_jsp.java:31)
> >> org.apache.jsp.users_jsp._jspService(users_jsp.java:164)
> >> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> >> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> >>
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
> >> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
> >> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
> >> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> >>
> >> I have not found anything I can do with this on the internet. Perhaps
> I've
> >> found that I might have a relation to
> >> timeBetweenEvictionRunsMillis parameter ( in <Resource> configuration
> >> section ).
> >>
> >> I don't know if it is important, here is my configuration in context.xml
> >> file:
> >>
> >> <Resource name="jdbc/onlineorder"
> >> auth="Container"
> >> type="javax.sql.DataSource"
> >> username="user"
> >> password="password"
> >> driverClassName="com.mysql.jdbc.Driver"
> >>
> url="jdbc:mysql://localhost/mydb?useUnicode=true&amp;characterEncoding=utf8"
> >> maxActive="10"
> >> maxIdle="5"
> >> testOnBorrow="true"
> >> testWhileIdle="true"
> >> timeBetweenEvictionRunsMillis="10000"
> >> minEvictableIdleTimeMillis="60000"
> >> />
> >>
> >> Did anyone face with this problem ?
> >
> > Exactly which version of the MySQL driver are you using?
> >
> > This is a side-effect of the memory leak prevention in Tomcat 6.0.20+
> > which aims to stop Timers that haven't been properly shutdown.
>
> Correction, Timer Thread termination was introduced in 6.0.24.
> It's optional from 6.0.27 with the clearReferencesStopTimerThreads flag.
>
> You might consider filing a bug with MySQL requesting that they check
> that the Timer is actually running.
>
>
> p
>
>
> p
>
>

Re: java.lang.IllegalStateException: Timer already cancelled

Posted by Pid <pi...@pidster.com>.
On 06/07/2010 08:22, Pid wrote:
> On 06/07/2010 08:05, Yevgen Krapiva wrote:
>> Hi guys.
>>
>> I have a servlet that uses connection pool with the use of MySQL driver.
>> When I start or reload Tomcat the application works fine, then if I
>> redeploy my application it cannot get a connection from a DataSource object.
>> The following exception is thrown:
>>
>> java.lang.IllegalStateException: Timer already cancelled.
>>
>> java.util.Timer.sched(Timer.java:354)
>> java.util.Timer.schedule(Timer.java:222)
>> org.apache.tomcat.dbcp.pool.impl.EvictionTimer.schedule(EvictionTimer.java:64)
>> org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.startEvictor(GenericObjectPool.java:1647)
>> org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.setTimeBetweenEvictionRunsMillis(GenericObjectPool.java:843)
>> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1173)
>> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
>> basis.onlineorder.commons.dao.UserDAOJdbcImpl.getUsers(UserDAOJdbcImpl.java:133)
>> org.apache.jsp.users_jsp.getUsersList(users_jsp.java:31)
>> org.apache.jsp.users_jsp._jspService(users_jsp.java:164)
>> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
>> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
>> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
>> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>>
>> I have not found anything I can do with this on the internet. Perhaps I've
>> found that I might have a relation to
>> timeBetweenEvictionRunsMillis parameter ( in <Resource> configuration
>> section ).
>>
>> I don't know if it is important, here is my configuration in context.xml
>> file:
>>
>> <Resource name="jdbc/onlineorder"
>> auth="Container"
>> type="javax.sql.DataSource"
>> username="user"
>> password="password"
>> driverClassName="com.mysql.jdbc.Driver"
>> url="jdbc:mysql://localhost/mydb?useUnicode=true&amp;characterEncoding=utf8"
>> maxActive="10"
>> maxIdle="5"
>> testOnBorrow="true"
>> testWhileIdle="true"
>> timeBetweenEvictionRunsMillis="10000"
>> minEvictableIdleTimeMillis="60000"
>> />
>>
>> Did anyone face with this problem ?
> 
> Exactly which version of the MySQL driver are you using?
> 
> This is a side-effect of the memory leak prevention in Tomcat 6.0.20+
> which aims to stop Timers that haven't been properly shutdown.

Correction, Timer Thread termination was introduced in 6.0.24.
It's optional from 6.0.27 with the clearReferencesStopTimerThreads flag.

You might consider filing a bug with MySQL requesting that they check
that the Timer is actually running.


p


p


Re: java.lang.IllegalStateException: Timer already cancelled

Posted by Pid <pi...@pidster.com>.
On 06/07/2010 08:05, Yevgen Krapiva wrote:
> Hi guys.
> 
> I have a servlet that uses connection pool with the use of MySQL driver.
> When I start or reload Tomcat the application works fine, then if I
> redeploy my application it cannot get a connection from a DataSource object.
> The following exception is thrown:
> 
> java.lang.IllegalStateException: Timer already cancelled.
> 
> java.util.Timer.sched(Timer.java:354)
> java.util.Timer.schedule(Timer.java:222)
> org.apache.tomcat.dbcp.pool.impl.EvictionTimer.schedule(EvictionTimer.java:64)
> org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.startEvictor(GenericObjectPool.java:1647)
> org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.setTimeBetweenEvictionRunsMillis(GenericObjectPool.java:843)
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1173)
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
> basis.onlineorder.commons.dao.UserDAOJdbcImpl.getUsers(UserDAOJdbcImpl.java:133)
> org.apache.jsp.users_jsp.getUsersList(users_jsp.java:31)
> org.apache.jsp.users_jsp._jspService(users_jsp.java:164)
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> 
> I have not found anything I can do with this on the internet. Perhaps I've
> found that I might have a relation to
> timeBetweenEvictionRunsMillis parameter ( in <Resource> configuration
> section ).
> 
> I don't know if it is important, here is my configuration in context.xml
> file:
> 
> <Resource name="jdbc/onlineorder"
> auth="Container"
> type="javax.sql.DataSource"
> username="user"
> password="password"
> driverClassName="com.mysql.jdbc.Driver"
> url="jdbc:mysql://localhost/mydb?useUnicode=true&amp;characterEncoding=utf8"
> maxActive="10"
> maxIdle="5"
> testOnBorrow="true"
> testWhileIdle="true"
> timeBetweenEvictionRunsMillis="10000"
> minEvictableIdleTimeMillis="60000"
> />
> 
> Did anyone face with this problem ?

Exactly which version of the MySQL driver are you using?

This is a side-effect of the memory leak prevention in Tomcat 6.0.20+
which aims to stop Timers that haven't been properly shutdown.

The problem is probably that the driver is located in the common
classloader and that Tomcat is discovering and killing the Timer it
starts when the webapp classloader is terminated.

Which gives me an idea...


p