在SBT上使用Scala的EBean(InterruptedException:sleep interrupted)

时间:2012-06-30 07:42:28

标签: scala exception sbt ebean interrupted-exception

我正在尝试在SBT上使用Scala运行EBean,但我收到错误。

这是代码(来自http://www.avaje.org/ebean/getstarted_props.html#test的测试):

object Main extends App {
    val sql = "select count(*) as count from dual"
    val row = Ebean.createSqlQuery(sql).findUnique()
    val i = row.getInteger("count")
    println("Got " + i + "  - DataSource good.")
}

这是错误:

[info] Loading project definition from /Volumes/etam/lift/hello-ebean/project
[info] Set current project to Main (in build file:/Volumes/etam/lift/hello-ebean/)
[info] Running hello.Main 
2012-06-30 09:36:51 com.avaje.ebeaninternal.server.core.BootupClassPathSearch search
INFO: Classpath search hits in jars[ebean-2.7.7.jar] pkgs[com.avaje.ebeaninternal.server.bean, com.avaje.ebean.meta]  searchTime[51]
2012-06-30 09:36:51 com.avaje.ebeaninternal.server.lib.sql.DataSourcePool initialise
INFO: DataSourcePool [h2] autoCommit[false] transIsolation[READ_COMMITTED] min[1] max[25]
2012-06-30 09:36:51 com.avaje.ebeaninternal.server.core.DefaultServerFactory setDatabasePlatform
INFO: DatabasePlatform name:h2 platform:h2
2012-06-30 09:36:51 com.avaje.ebeaninternal.server.subclass.SubClassManager$1 run
INFO: SubClassFactory parent ClassLoader [sbt.classpath.ClasspathUtilities$$anon$1]
2012-06-30 09:36:51 com.avaje.ebeaninternal.server.deploy.DeployOrmXml findAllOrmXml
INFO: Deployment xml [orm.xml]  loaded.
2012-06-30 09:36:51 com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager logStatus
INFO: Entities enhanced[0] subclassed[0]
runScript
executing 1 of 2 SET REFERENTIAL_INTEGRITY FALSE
executing 2 of 2 SET REFERENTIAL_INTEGRITY TRUE
... end of script
runScript
... end of script
2012-06-30 09:36:51 com.avaje.ebeaninternal.server.transaction.log.FileTransactionLoggerWrapper initialiseLogger
INFO: Transaction logs in: logs
Got 0  - DataSource good.
2012-06-30 09:36:51 com.avaje.ebeaninternal.server.lib.BackgroundThread$Runner run
SEVERE: null
java.lang.InterruptedException: sleep interrupted
    at java.lang.Thread.sleep(Native Method)
    at com.avaje.ebeaninternal.server.lib.BackgroundThread$Runner.run(BackgroundThread.java:168)
    at java.lang.Thread.run(Thread.java:680)
2012-06-30 09:36:51 com.avaje.ebeaninternal.server.transaction.log.FileTransactionLogger run
INFO: Interrupted TxnLogBufferWriter
java.lang.InterruptedException: sleep interrupted
    at java.lang.Thread.sleep(Native Method)
    at com.avaje.ebeaninternal.server.transaction.log.FileTransactionLogger.run(FileTransactionLogger.java:206)
    at java.lang.Thread.run(Thread.java:680)
[success] Total time: 1 s, completed 2012-06-30 09:36:51

该项目有什么问题?

GIT存储库:https://github.com/odwrotnie/hello-ebean; 主要班级:https://github.com/odwrotnie/hello-ebean/blob/master/main/src/main/scala/hello/main.scala; config:https://github.com/odwrotnie/hello-ebean/blob/master/main/src/main/resources/ebean.properties

提前致谢, 艾格。

1 个答案:

答案 0 :(得分:2)

默认情况下,run在与sbt本身相同的jvm中执行应用程序,以缩短周转​​时间。在这种情况下,run认为在main方法终止后只剩下守护程序线程。它继续中断那些剩余的线程,这给出了你看到的例外。它必须这样做,因为这是伪造jvm关闭而不实际关闭它的最佳方法。

这些异常看起来并不太危害,但你可以通过在分叉的jvm中运行应用程序来摆脱它们。要启用此功能,请将以下内容添加到构建设置

fork in run := true

sbt如何在同一个jvm中运行项目代码如下所述:http://www.scala-sbt.org/release/docs/Detailed-Topics/Running-Project-Code.html

此处描述了分叉:http://www.scala-sbt.org/release/docs/Detailed-Topics/Forking.html