It is easy to reproduce:
1. Create new play application
2. Create empty mysql database and enable mysql in application.conf:
db=mysql:root@printjob
(note, bug is not reproducible with in-memory database)
3. Create PrintJob class:
package jobs;
import play.jobs.*;
@Every("10s")
public class PrintJob extends Job {
public void doJob() {
System.out.println("Job executed");
}
}
4. play run, browse to start application
Now if you change 10s to 5s in @Every annotation you get a following:
13:27:43,143 ERROR ~ Cannot connected to the database : An SQLException was provoked by the following failure: java.lang.InterruptedException
java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:62)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:531)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at play.db.DBPlugin.onApplicationStart(DBPlugin.java:75)
at play.Play.start(Play.java:359)
at play.Play.detectChanges(Play.java:451)
at play.Invoker$Invocation.init(Invoker.java:98)
at play.jobs.Job.call(Job.java:103)
at play.jobs.Job.run(Job.java:97)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:637)
Caused by: java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1315)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 16 more
13:27:43,151 ERROR ~
@61k7nf97e
Error during job execution (jobs.PrintJob)
Database error
A database error occured : Cannot connected to the database. Check the configuration.
play.exceptions.DatabaseException: Cannot connected to the database. Check the configuration.
at play.db.DBPlugin.onApplicationStart(DBPlugin.java:86)
at play.Play.start(Play.java:359)
at play.Play.detectChanges(Play.java:451)
at play.Invoker$Invocation.init(Invoker.java:98)
at play.jobs.Job.call(Job.java:103)
at Invocation.Job(Play!)
Caused by: java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:62)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:531)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at play.db.DBPlugin.onApplicationStart(DBPlugin.java:75)
... 5 more
Caused by: java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1315)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 7 more
After that job is not executed anymore until play is restarted.
After some experiments:
- It is not necessary to change @Every annotation. Any change to any file in application (tested with application.conf and models) causes next job to fail with database error.
- If I browse any application page after job's database error, functionality is restored and job works again (until next modification of any project file).
- If I use @On annotation instead of @Every - everything is fine and changes doesn't cause any errors.