BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Akka Actors vs. Java EJBs from a High-Level Concurrency Perspective

by Jan Stenberg on Feb 27, 2014 |

When comparing architectural principles and coding styles in Akka Actors and Java EE 7 Enterprise JavaBeans, specifically stateless session beans and JMS message-driven beans, there are commonalities, e.g. all three types are capable of both vertical and horizontal scaling, and some differences, e.g. in exception and transaction handling, Dr Gerald Loeffler concludes in a recent introductory talk when explaining and comparing the three approaches from a high-level concurrency view.

For his talk Gerald, a Senior Integration Architect, defines high-level concurrency as a programming paradigm where the concurrency is handled at the level of components and is abstracted away as much as possible, above handling individual threads or individual tasks and submitting those to thread pools.

He structures his talk around the idea of the Active Objects design pattern, loosely related to the classic design pattern but with the same kind of ideas. The examples are in Scala but he believes the talk is equally relevant for Java.

A simple mental model from an Active Objects perspective is for Gerald that:

  • Akka Actors receive messages as arbitrary objects, enqueued in a mailbox. They are explicitly managed and addressed individually via a common interface.
  • Stateless Session Beans expose asynchronous methods executed in an application server with lifecycle controlled by the container.
  • JMS Message-Driven Beans receive and process messages of predefined types from a JMS queue/topic. They are container-managed in the same way as session beans.

A common behaviour is that all three types execute asynchronously on threads, typically from a pool, with serialized access to the same instance.

Gerald uses three patterns for his comparison with code examples for all three types:

  • Local One-Way Asynchronous Request where an asynchronous request is sent from a requestor to a responder, who will not respond.
  • Request Asynchronous Out-of-Context Request where a requestor sends a message to a responder who sends back a return message, and when received the requestor has to re-establish the context.
  • Request Asynchronous In-Context Request where the context in some way has been preserved by the requestor when the return message is received.

Finally, Gerald concludes with a short summary of commonalities, e.g. all three approaches uses thread pools and are capable of both vertical and horizontal scaling, and some important differences, e.g. in exception handling, supervisor strategies and transaction handling.

Akka is an open source toolkit and runtime for building concurrent and event-driven applications on the JVM.
Enterprise Java Beans, EJB, is part of the larger Java EE specification, currently Java EE 7.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

slides with code by Gerald Loeffler

The slides for this talk (incl. Scala code) are available at www.gerald-loeffler.net/download/high_level_concurrency_scala_lsug_2014-02-05.pdf.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT