Search code examples
jettycontinuations

What are "Jetty 6 Continuations" and how do they compare to the continuations found in programming languages?


I'm looking for an answer that describes a "continuation" mechanism in a web server vs. a programming language.

My understanding is that using continuations, it is trivial to have a "digits of pi" producer communicate with a "digits of pi" consumer, without explicit threading.

I've heard very good things about Jetty continuations. I am curious what others think.

I may have already found my answer, but I'm asking the question here anyway - for the record.


Solution

  • how do they compare to the continuations found in programming languages?

    They have nothing in common apart from the name. It's merely a mechanism for freeing the current thread by giving Servlet an API for storing and restoring its state, but it's all rather manually managed as opposed to real continuations, where the state is automatically inferred from the current context.

    The prototypical example for cases where this makes sense is layered (composed) web services, where one service needs to make many requests to other services, and while these requests are made, the current thread is freed. Upon completions of the requests (which can be done asynchronously on some other threads), the servlet's resume method is called, which then will assemble the response from the results of the requests.