Adam Bien's Weblog

Wednesday Feb 12, 2014

JavaEE 7 - Injecting A ManagedExecutorService

Legacy resources can be easily integrated with JavaEE 7 in a robust way using the JSR 236: Concurrency Utilities for Java EE 7

Thanks for watching!

See also other screencasts at: or subscribe to

See you at Java EE 7 Workshops at MUC Airport or on demand and in a location very near you:!

NEW: Java EE 7 Testing and Quality Workshop

A book about rethinking Java EE Patterns


What was that ? How can I unseen my 3 minutes ?

Posted by on February 12, 2014 at 12:05 PM CET #


this was just an answer to multiple Java EE / concurrency questions I got. Instead of writing multiple emails, I just recorded a screencast.

a follow-up is coming,

thanks for watching! Btw. You not only spent 3 minutes watching this, but also about 1 min commenting. So in total you spent about 4 mins...



Posted by Adam Bien on February 12, 2014 at 02:13 PM CET #


In jee 6 I used: "ExecutorService executor = Executors.newFixedThreadPool(THREADS);". Please explain me what differs ManagedExecutorService from "old standard" ExecutorService, and why should I use @Resource injection over static factory method ?

Posted by Marek on February 14, 2014 at 11:26 AM CET #


a ManagedExecutorService provides you with the following additional features:

1.Monitoring: an application server will be able to report back the current amount of threads etc.
2. Management / Configuration: with MES it is trivial to change the thread pool configuration any settings without recompiling the application.
3. Context: MES provides tasks with additional context like e.g. security.
4. Robustness: starting application managed threads can quickly overload the application server. In the past I got some contracts to solve such problems :-)

enjoy Java!,


Posted by Adam Bien on February 14, 2014 at 02:07 PM CET #

Hi Adam,

Sorry this may be a little off topic.

My question is:
I have several EJB timers which perform some background tasks (like a robot/agent). Where should I put these classes under the ECB (Entity-Control-Boundary) scope?



Posted by David on February 16, 2014 at 08:53 AM CET #

Hi Adam!

Could you please elaborate on the purpose of this video? You say that it's the only legal way to run threads in Java EE 6, so I have 2 questions:

1) Why are you running this on Java EE 7? As far as I understand the preferred way to run multithreaded apps in Java EE 7 is with ManagedExecutorService. Or am I wrong?

2) Why do we need Runnable at all in this example? The EJB doesn't start a new Thread, it just executes a run() method. So, instead of passing Runnable, we could as well pass some Command object.

Posted by Anton on February 16, 2014 at 08:29 PM CET #


I think you are referring to another video ("EJBs as Executors":

1.) I ran this video on JavaEE 7, because all my projects are JavaEE 7 projects and I was too lazy to downgrade the server to JavaEE 6

2.) You don't need Runnable at all. However: with the Runnable-trick you can pass any legacy runnable-implementation and it is getting to be executed in a managed way. It is actually a Command pattern.

cheers && thanks for your comment,


Posted by Adam Bien on February 17, 2014 at 11:36 AM CET #


I usually put timers to the control package. However: if the timers coordinate multiple controls and act more like a facade, then I would put them to the boundary package.

cheers && thanks for asking about ECB,


Posted by Adam Bien on February 17, 2014 at 11:37 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments