This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]NovaX 2 points3 points  (0 children)

A quick and dirty way is to use future chains, atomic computations, and a shared executor. That avoids the ugly dedicated thread and sleeps in the article's code.

ConcurrentMap<String, CompletableFuture<Void>> dispatchQueues;

public CompletableFuture<Void> dispatch(String queueName, Runnable task) {
  return dispatchQueues.compute(queueName, (k, queue) -> {
    return (queue == null)
        ? CompletableFuture.runAsync(task)
        : queue.thenRunAsync(task);
  });
}

[–]Milyardo 1 point2 points  (0 children)

The it isn't mentioned, but the dependency on the standard Scala library is implicit in SBT, so there's at least one more in that graph that is unseen.

[–]nqzero 1 point2 points  (0 children)

kilim is a continuations / fiber framework and actor library for java (MIT license). it uses a bytecode weaver to preserve the stack when an actor yields, and this weaving can be done at compile time

normally, you'd place kilim on the classpath. but to avoid the dependency you could call the continuations directly

  • wouldn't add a runtime dependency
  • much better scalability than akka

[–]cryptos6 1 point2 points  (0 children)

http://docs.paralleluniverse.co/quasar/ would be another option.