Is there a good implementation of continuations in Java?
If so, what is the overhead like? The JVM wasn\'t designed with these sort of things in mind, right? So is t
If you don't mind implicit continuations, Kilim is a great option. It works by processing annotated methods and generating the continuations in bytecode for you. Obviously it does a lot more since it's a framework, but if you want the (excellent) performance of thread-safe continuations, it's worth a look.
Another library by Matthias Mann:
http://www.matthiasmann.de/content/view/24/26/
http://www.matthiasmann.de/java/Continuations/
Scala also runs on JVM. So it might be relevant.
What are Scala continuations and why use them?
In addition Scala has somewhat similar async/await feature:
http://docs.scala-lang.org/sips/pending/async.html
Play! framework version 1.2.x also has support for continuations integrated with async http goodies.
Note that Play 1.2.x continuations only work with the inbuilt Netty server.
And Play 2.x still has no support for continuations.
Consider also Kotlin Coroutines.
It's implemented via potentially more performant CPS transformations (still stackful) and can use any async executor under the hood like ForkJoinPool or Quasar integration.
Comes with handy guided library.
Beware of some tooling and reflection pitfalls.
Jetty has continuation support. There is further discussion and some samples at DZone.
I can't advise on the efficiencies or otherwise, other than to say that the Mortbay team always appear concious of such issues. There will most likely be a discussion of implementation trade-offs somewhere on the Jetty site.