打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Continuations

Continuations refer to a functional programming technique that allows you to save the current execution state of a thread, with the possiblity of suspending and later resuming execution.

 

It can simplify complex workflows. Instead of creating an external control flow as individual steps that are tied together with navigation rules or state transitions, continuations provide a much simpler model—almost as simple as if you were doing console programming in the early DOS days.

 

With continuations, when you need to get a response from a user, you only need to say so: the execution of the server-side process will then halt and preserve everything that is going on for that particular process. When the next request from the user comes in, the server-side process resumes exactly where it left off before. It‘s just like when you save and resume a game.

 

Continuations free you from having to worry about where you are in the process, or what next steps you can take, or which elements of the session are entered into at what point in the execution.

 

The way that works is that continuations let you save the method call stack as well as the variable stack.

 

RIFE and Webwork support this concept.

 

Implementation in RIFE is to rewrite byte code to be loaded. API calls (pause()) to RIFE are acting as Markers. In the place of Marker, RIFE instruments some byte code to aggregate current state of method call stack and value stack. RIFE maintains a parallel stack referencing the actual data.

 

The bit of overhead that occurs is the result of the fact that you typically make a deep clone of the actual data at the next continuation. This is needed because each continuation needs to be totally independent of another one.

 

The only restrictions developers have in using continuations is that the data structure must be cloneable or serializable so that the infrastructure can create carbon copies of those data structures.

 

There is a continuation manager. It even would be statefully replicated in order to support stateful fail-over in the near future (in conjunction with Terracotta DSO ).

 

Continuation can let you save the state of execution.

It can be used to improve polling-based approach in a event-driven system. You don‘t need to poll manually. You only need an event to resume the execution of a continuation.

 

Special method call is pause(), call() and stepBack(). Pause()  you indicate one specific location you‘re interested in.

When pause() is called that continuation would stop, before that the content to user must have been flushed to sevlet container to let it render them for end-user. And the next request from the user will contain the continuation Id. The continuation manager will resume the previously stopped continuation.

 

http://www.artima.com/lejava/articles/continuations.html

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Frames
Programming in Lua(六)-Continuation ? 技术奇异点
What is the Execution Context & Stack in JavaScript? by David Shariff
Struts学习笔记(一)
How the Java Virtual Machine (JVM) Works
UIElement.InvalidateVisual
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服