Continuations in Java

Is there a good implementation of continuations in Java?

If so, what are the overheads? The JVM was not designed with such things, right? So does it go against the grain?

+25
java continuations
Sep 21 '09 at 18:36
source share
10 answers

See Apache Javaflow http://commons.apache.org/sandbox/javaflow/

This is the only continuation package for Java that is being actively developed. The other, RIFE, I'm not sure what condition it is in.

+12
Sep 07 '10 at 2:19
source share

Jetty has continuation support. The following is a discussion of several examples on DZone .

I cannot advise on performance or otherwise, except to say that the Mortbay team always seems fascinating on such issues. Most likely, there will be a discussion of implementation compromises somewhere on the Jetty website.

+7
Sep 21 '09 at 18:39
source share

If I get it right, I assume the obvious problem is to expand the stack with active instances of closure. I believe that a language with a lexical domain could theoretically figure out that a child frame can instantiate a closure, identify those intermediate frames that are referenced, and then it can malloc these frames instead of just pushing them onto the stack.

In this case, the compiler can malloc all frames or all parent closure frames that reference an object that is not bound to global objects.

Summary

I don’t think the JVM limits the closure more than the real machine, they just struggle with the overall stack paradigm, and therefore they usually get fined.

+2
Sep 21 '09 at 18:48
source share

If you don't mind implicit continuations, Kilim is a great option. It works by processing annotated methods and generating bytecode sequel for you. Obviously, this does a lot more, since it is a framework, but if you want the (excellent) performance of thread-safe continuations, it's worth a look.

+2
Aug 13 2018-12-18T00:
source share

Play! framework version 1.2.x also has continuation support integrated with asynchronous http files.

Please note that Play 1.2.x extensions only work with the built-in Netty server .

And Play 2.x still does not support sequels .

+1
Oct 19 '12 at 15:34
source share

Recently, another strong competitor has appeared.

Quasar uses forked from Matthias Mann's implementation of java sequels to provide higher level functions such as lightweight streams , Erlang-like members, and Go-like coroutines and channels .

The Quasar Blog block has many tests and detailed presentations.

There is also a ready-to-use integration called Comsat , which aims to simplify the creation of web services based on continuation mechanisms under the hood.

Quasar also provides the good Kotlin API, which was featured at the recent Quasar JetBrains webinar : efficient and elegant fibers, channels, and actors .

All of the above is open source and free to use.

+1
Jun 13 '16 at 12:32
source share

Scala also runs on the JVM. Therefore, this may be relevant.

What are Scala sequels and why use them?

In addition, Scala has a somewhat similar async / await function:

http://docs.scala-lang.org/sips/pending/async.html

0
Dec 04 '13 at 6:43
source share
0
Apr 23 '14 at 10:07
source share

Starting with Java 8, there is now the class CompletableFuture<T> , which supports continuation and more functional / reactive programming approaches.

Consider the following example where the class offers the downloadAndResize method:

 public CompletableFuture<Image> downloadAndResize(String imageUrl, int width, int height) { return CompletableFuture .supplyAsync(() -> downloadImage(imageUrl)) .thenApplyAsync(x -> resizeImage(x, width, height)); } private Image downloadImage(String url){ // TODO Download the image from the given url... } private Image resizeImage(Image source, int width, int height){ // TODO Resize the image to w / h } 

Using the above method might look like this:

 CompletableFuture<Image> imagePromise = downloadAndResize("http://some/url", 300, 200); imagePromise.thenAccept(image -> { // Gets executed when the image task has successfully completed // do something with the image }); 
0
May 9 '15 at 9:19
source share



All Articles