Slick 3.0-RC3 fails with java.util.concurrent.RejectedExecutionException

假装没事ソ 提交于 2019-11-28 14:13:33
Aldo Stracquadanio

I think that something is not correct in what you are trying to do: Slick's run method doesn't return Unit and doesn't fail with an exception - as it used to in previous versions. run now returns a Future, so if you want to run actions in sequence you need to flatMap the steps, or use a for-comprehension:

def init() = {
  val = results for {
    _ <- db.run(dal.create)
    _ <- db.run(dal.stuffTable += Stuff(23, "hi"))
    r <- db.run(dal.stuffTable.filter(_.serial === 23).result)
  } yield r
}

I am not sure that you really need to use db.close that way: that is actually what may be causing the error (i.e. the db is closed in concurrence with the future that runs the actual queries so the execution can't happen).

If you want to handle errors use Future's capabilities, e.g.:

result.onFailure { case NonFatal(ex) => // do something with the exception }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!