You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importscala.concurrent.ExecutionContext.Implicits.globalimportscala.concurrent.{ Await, Future }
importscala.concurrent.duration._objectFutureTest {
defprintIdInfo(id: Long):String= {
if (id %2==0) {
"even:%s".format(id)
} else {
"odd:%s".format(id)
}
}
println(s"Current thread: ${printIdInfo(Thread.currentThread().getId)}")
valfuture:Future[Unit] =Future(println {
s"Thread id in future: ${printIdInfo(Thread.currentThread().getId)}."
})
Await.result(future, 2.seconds)
println("Future has been executed")
}
FutureTest
problem
(explain how the above behavior isn't what you expected)
Current thread: odd:1
java.lang.NoClassDefFoundError: Could not initialize class $line6.$read$$iw$$iw$$iw$$iw$FutureTest$
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)
at scala.util.Success.$anonfun$map$1(Try.scala:255)
at scala.util.Success.map(Try.scala:213)
at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:33)
at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:33)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
java.util.concurrent.TimeoutException: Futures timed out after [2 seconds]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:259)
at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:263)
at scala.concurrent.Await$.$anonfun$result$1(package.scala:223)
at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:57)
at scala.concurrent.Await$.result(package.scala:146)
... 30 elided
The text was updated successfully, but these errors were encountered:
As a refresher, "fixed in dotty" because bootstrap methods are non-static so the future lambda does not block for static init of module. However, fields are static, so any data references will deadlock again.
reproduction steps
using Scala (2.11.12, 2.12),
problem
(explain how the above behavior isn't what you expected)
The text was updated successfully, but these errors were encountered: