<div dir="ltr">Here you have it: <a href="https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/util/SerializedSuspendableExecutionContext.scala">https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/util/SerializedSuspendableExecutionContext.scala</a><div>
<br></div><div style>If you're only on plain Java, search-and-replace ExecutionContext with j.u.c.Executor</div><div style><br></div><div style>(It is also susspendable and resumable)</div><div style><br></div><div style>
Cheers,</div><div style>√</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Feb 17, 2013 at 10:35 PM, Jeff Hain <span dir="ltr"><<a href="mailto:jeffhain@rocketmail.com" target="_blank">jeffhain@rocketmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:10pt;font-family:Courier New,courier,monaco,monospace,sans-serif">Hi.<div class="im"><br><br>
<br><br>Feng Shen wrote:<br>>Would appreciate for any thought about how to design such a thread pool?<br><br><br><br></div>It seems to me you don't need a particular thread pool to have some of your<br>tasks ordered, if you can keep a reference to last submitted runnable for each<br>
ordered sequence of runnables (for example using a map in IO thread).<br><br><br>I'm thinking about using a specific "LinkingRunnable", containing<br>an "impl" Runnable and an AtomicReference to a "next" Runnable.<br>
<br><br>When LinkingRunnable.run() is called, it first runs impl.run(), and then<br>does CAS(null,this) (using "this" as a tombstone): if CAS fails, that means<br>someone added a runnable to run next, and it runs it.<br>
<br><br>When subsequent task arrives, you try to "enqueue" it doing CAS(null,next):<br>If CAS
 succeeds, that means it'll be executed just after previous task<br>(and in same thread), and if it fails that means that the previous task<br>already completed, so you can just submit your next task to the pool.<br>
<br><br>You can also test "get() == null" before doing CASes, which should<br>make them rare, and reduce the usual overhead to a volatile read.<span class="HOEnZb"><font color="#888888"><br><br><br><br>-Jeff<br>
<br> <div style="font-family:Courier New,courier,monaco,monospace,sans-serif;font-size:10pt"> </div>  </font></span></div></div><br>_______________________________________________<br>
Concurrency-interest mailing list<br>
<a href="mailto:Concurrency-interest@cs.oswego.edu">Concurrency-interest@cs.oswego.edu</a><br>
<a href="http://cs.oswego.edu/mailman/listinfo/concurrency-interest" target="_blank">http://cs.oswego.edu/mailman/listinfo/concurrency-interest</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><span style="border-collapse:separate;color:rgb(0,0,0);font-family:Times;font-variant:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium"><span style="font-family:arial;font-size:small"><span style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px"><b style="font-style:normal">Viktor Klang</b><br>
<i>Director of Engineering</i></span></span></span><div><font color="#000000"><i><br></i></font><span style="border-collapse:separate;color:rgb(0,0,0);font-family:Times;font-variant:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium"><span style="font-family:arial;font-size:small"><div style="font-style:normal;font-weight:normal">
<font face="arial, sans-serif"><span style="border-collapse:collapse"><a href="http://www.typesafe.com/" target="_blank">Typesafe</a><span> </span>- </span></font><span>The software stack for applications that scale</span><font face="arial, sans-serif"><span style="border-collapse:collapse"><br>
</span></font><font face="arial, sans-serif"><span style="border-collapse:collapse">Twitter: @viktorklang</span></font></div></span></span></div></div>
</div>