Discussion:
DefaultManagedExecutorService lookup in JNDI
Paul Carter-Brown
2017-10-10 22:13:11 UTC
Permalink
Hi,

According to EE7 spec I should be able to do the following:

try {
new
InitialContext().lookup("java:comp/DefaultManagedExecutorService");
} catch (NamingException e) {
log.warn("Error:", e);
}

In TomEE 7.0.4 I get a NamingException:

javax.naming.NameNotFoundException: Name [DefaultManagedExecutorService] is
not bound in this Context. Unable to find [DefaultManagedExecutorService].
at org.apache.naming.NamingContext.lookup(NamingContext.java:816)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.test.beanmanagerbug.MyServlet.init(MyServlet.java:36)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at
org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)
at
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4931)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5241)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at
org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at
org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Any idea how I can get the DefaultManagedExecutorService in an unmanaged
bean (i.e. using JNDI)

Thanks
Paul
--
This email is subject to the disclaimer of Smile Communications at http://www.smilecoms.com/home/email-disclaimer/ <http://www.smilecoms.com/disclaimer>
Romain Manni-Bucau
2017-10-10 22:47:49 UTC
Permalink
Hi

You need to set openejb.environment.default=true. Idea is to skip resources
which uses machine resources by default to stay usable in all environments.
Alternative is to use a pool impl executing tasks synchronously bit would
quite useless IMHO.
Post by Paul Carter-Brown
Hi,
try {
new
InitialContext().lookup("java:comp/DefaultManagedExecutorService");
} catch (NamingException e) {
log.warn("Error:", e);
}
javax.naming.NameNotFoundException: Name [DefaultManagedExecutorService] is
not bound in this Context. Unable to find [DefaultManagedExecutorService].
at org.apache.naming.NamingContext.lookup(NamingContext.java:816)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.test.beanmanagerbug.MyServlet.init(MyServlet.java:36)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at
org.apache.catalina.core.StandardWrapper.initServlet(
StandardWrapper.java:1183)
at
org.apache.catalina.core.StandardWrapper.loadServlet(
StandardWrapper.java:1099)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)
at
org.apache.catalina.core.StandardContext.loadOnStartup(
StandardContext.java:4931)
at
org.apache.catalina.core.StandardContext.startInternal(
StandardContext.java:5241)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at
org.apache.catalina.core.ContainerBase$StartChild.call(
ContainerBase.java:1419)
at
org.apache.catalina.core.ContainerBase$StartChild.call(
ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(
ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(
ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Any idea how I can get the DefaultManagedExecutorService in an unmanaged
bean (i.e. using JNDI)
Thanks
Paul
--
This email is subject to the disclaimer of Smile Communications at
http://www.smilecoms.com/home/email-disclaimer/ <http://www.smilecoms.com/
disclaimer>
agumbrecht
2017-10-10 23:46:14 UTC
Permalink
Properties are somewhat documented here:
http://tomee.apache.org/admin/configuration/server.html - It's not totally
obvious in your case that the property named here does what Romain
describes, but please feel free to create a ticket on the jira here:
https://issues.apache.org/jira/browse/TOMEE if you would like a better
description.

The managed executor is a way to start threads that the server will attempt
to stop on a shutdown. The app server is already multithreaded, so there
might be a better way to do what you are intending?

Andy.



-----
--
Andy Gumbrecht

http://www.tomitribe.com
***@tomitribe.com
https://twitter.com/AndyGeeDe

TomEE treibt Tomitribe ! | http://tomee.apache.org
--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Paul Carter-Brown
2017-10-11 08:10:44 UTC
Permalink
This post might be inappropriate. Click to display it.
Romain Manni-Bucau
2017-10-11 08:17:32 UTC
Permalink
It defines the link only, which means it does the same as your
@Resource. Difference is that if you don't have any @Resource then it
would still do it if true by default. Then if there is a link and no
matching resource then openejb creates one implicitly. This means that
false is a good default avoiding to create not needed resources :).

Romain Manni-Bucau
@rmannibucau | Blog | Old Blog | Github | LinkedIn
Post by Paul Carter-Brown
Thanks Romain/Andy,
openejb.environment.default = true fixed it
Does this property merely indicate that the resources should be bound into
the JNDI tree or does it control whether they are created or not by the
container?
I found it interesting that this works fine even with that property set to
@Resource
private ManagedExecutorService mes;
~~~
The systems we build almost always do a lot in the background in addition
to servicing incoming requests over HTTP and other protocols. Background
threads are needed to do things like service discovery, service monitoring,
rating, event processing, polling external systems etc etc. I bootstrap
this "background" functionality via a servlet with loadOnStartup and an
init function that would kick everything off. I was experimenting with
moving all this background code to be loaded and managed by CDI. As the
initial servlet init function is within a managed context I could inject
from there on into the code base to boot everything up. I was thinking of
they could do their thing with executors in the background. My recent
circumstances with multiple skinny wars in a EAR lead me to rethink using
CDI and rather use good old Singletons where I can fully control the
lifecycle of the instance and be sure its background processing is only
started once. Instead of creating my own threads I'd prefer to use
ManagedExecutorService and ManagedScheduledExecutorService. It was easy to
get these when I could inject them but now with singletons and classes that
are being created outside of the managed context (i.e. with
and this is where I hit this particular issue.
Paul
Post by agumbrecht
http://tomee.apache.org/admin/configuration/server.html - It's not totally
obvious in your case that the property named here does what Romain
https://issues.apache.org/jira/browse/TOMEE if you would like a better
description.
The managed executor is a way to start threads that the server will attempt
to stop on a shutdown. The app server is already multithreaded, so there
might be a better way to do what you are intending?
Andy.
-----
--
Andy Gumbrecht
http://www.tomitribe.com
https://twitter.com/AndyGeeDe
TomEE treibt Tomitribe ! | http://tomee.apache.org
--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-
f979441.html
--
*Paul Carter-Brown*
*Group Chief Information Officer*
*Smile Communications Pty (Ltd) *
Smile +234 (0) 702 000 1234
Mobile +27 (0) 83 4427 179
Skype PaulC-B
www.smilecoms.com
--
This email is subject to the disclaimer of Smile Communications at http://www.smilecoms.com/home/email-disclaimer/ <http://www.smilecoms.com/disclaimer>
Andy Gumbrecht
2017-10-12 06:07:02 UTC
Permalink
Hi Paul,

You might like to consider investigating the @Asynchronous annotation.
It could solve a few of your headaches, without requiring the
ManagedExecutorService.

Here is a simple example - But it can do a lot more:
http://tomee.apache.org/examples-trunk/async-methods/ - It's basically
like a free and managed ManagedExecutorService without the overhead if
you get my drift?

Andy.
Post by Paul Carter-Brown
Thanks Romain/Andy,
openejb.environment.default = true fixed it
Does this property merely indicate that the resources should be bound into
the JNDI tree or does it control whether they are created or not by the
container?
I found it interesting that this works fine even with that property set to
@Resource
private ManagedExecutorService mes;
~~~
The systems we build almost always do a lot in the background in addition
to servicing incoming requests over HTTP and other protocols. Background
threads are needed to do things like service discovery, service monitoring,
rating, event processing, polling external systems etc etc. I bootstrap
this "background" functionality via a servlet with loadOnStartup and an
init function that would kick everything off. I was experimenting with
moving all this background code to be loaded and managed by CDI. As the
initial servlet init function is within a managed context I could inject
from there on into the code base to boot everything up. I was thinking of
they could do their thing with executors in the background. My recent
circumstances with multiple skinny wars in a EAR lead me to rethink using
CDI and rather use good old Singletons where I can fully control the
lifecycle of the instance and be sure its background processing is only
started once. Instead of creating my own threads I'd prefer to use
ManagedExecutorService and ManagedScheduledExecutorService. It was easy to
get these when I could inject them but now with singletons and classes that
are being created outside of the managed context (i.e. with
and this is where I hit this particular issue.
Paul
Post by agumbrecht
http://tomee.apache.org/admin/configuration/server.html - It's not totally
obvious in your case that the property named here does what Romain
https://issues.apache.org/jira/browse/TOMEE if you would like a better
description.
The managed executor is a way to start threads that the server will attempt
to stop on a shutdown. The app server is already multithreaded, so there
might be a better way to do what you are intending?
Andy.
-----
--
Andy Gumbrecht
http://www.tomitribe.com
https://twitter.com/AndyGeeDe
TomEE treibt Tomitribe ! | http://tomee.apache.org
--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-
f979441.html
--
Andy Gumbrecht
https://twitter.com/AndyGeeDe
http://www.tomitribe.com
https://www.tomitribe.io
Loading...