BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

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

| by Jan Stenberg Follow 5 Followers on Feb 27, 2014. Estimated reading time: 2 minutes |

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.

Rate this Article

Adoption Stage
Style

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.

Excellent by David Tonhofer

I love these efforts of carving out the principles between different approaches, getting rid of the irrelevant details and performing a side-by-side comparisons. It answers the question "underneath the sales pitch, what is this really and where have I seen this before?"

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

2 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT