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 this kind of going against the grain?
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 this kind of going against the grain?
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.
If I understand this correctly, I suppose the obvious problem involves unwinding the stack with closure instances active. I suppose a language with lexical scope could in theory figure out that a child frame may create a closure instance, identify those intermediate frames that are referenced, and then it could malloc those frames instead of just pushing them on the stack.
For that matter, a compiler could malloc all frames or all parent frames of a closure referencing a non-globally-bound object.
I don't think the JVM restricts closures any more than a real machine, it's just that they fight the general stack paradigm and so they usually get punted.
See Apache Javaflow http://commons.apache.org/sandbox/javaflow/
It's the only continuation package for java that's actively under development. The other one, RIFE, I'm not sure which state it's in.