2012-06-30 77 views
0

我想在SBT上用Scala運行EBean,並且出現錯誤。SBe上的Scala EBean(InterruptedException:睡眠中斷)

這是代碼(從測試: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

在此先感謝, Etam。

回答

2

默認情況下,run以與sbt本身相同的jvm執行應用程序,以縮短週轉​​時間。在這種情況下,run認爲主方法終止後只剩下守護進程線程。它繼續中斷那些剩下的線程,這給出了你看到的例外。它必須這樣做,因爲這是最好的,它可以僞造一個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