Discussion:
cannot use ManagedExecutorService resource
clemensx
2018-07-16 10:31:13 UTC
Permalink
Hi,

we have problems using ManagedExecutorService resources in tomee 7.0.4
Using default ManagedExecutorService works fine, but if we try to define a
new pool with more threads we cannot access the service

In resource.xml we do this:
<Resource id="FooManagedExecutorService" type="ManagedExecutorService">
Core = 40
Max = 50
KeepAlive = 5 s
Queue = 150
ThreadFactory = org.apache.openejb.threads.impl.ManagedThreadFactoryImpl
Lazy = true
</Resource>

But then we cannot even get the default service injected in our stateful
session bean:
@Resource(name="java:comp/DefaultManagedExecutorService")
private ManagedExecutorService execService;
will yield a null execService.

@Resource(name="FooManagedExecutorService")
private ManagedExecutorService execService;
same with trying to access our own resource.

Getting the reference programmatically via
execService = (ManagedExecutorService)
sessionContext.lookup(“openejb:Resource/FooManagedExecutorService”);
also gives null.


In the server startup logs we see several mentions of our service:

for all beans:
[CONTAINER] OpenEJB.startup.config INFO Auto-linking resource-ref
'openejb/Resource/ROOT/FooManagedExecutorService' in bean ProductDao to
Resource(id=FooManagedExecutorService)

3 times this info (no idea why the container is creating the resource 3
times):
[CONTAINER] OpenEJB.startup.service INFO Creating
Resource(id=ROOT/FooManagedExecutorService,
aliases=FooManagedExecutorService)

[CONTAINER] OpenEJB.startup.config INFO Configuring
Service(id=ROOT/FooManagedExecutorService, type=Resource,
provider-id=Default Executor Service)


Thanks for any ideas/workarounds
clemens




--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Romain Manni-Bucau
2018-07-16 12:10:47 UTC
Permalink
Hi

yes, this is normal. TomEE defines defaults and you can override them. To
supports all cases the defaults are auto-adjusted to the "prod" (hardcoded)
resources - very handy in tests.
If you don't activate openejb.offline=true then this is the behavior you
have, if you set it then no implicit/default resource are available.

This means that if you define a resource matching the default auto-created
one it will be considered as the default. This works until you define the
name of the resource. In this case you must ensure there is no ambiguity
and the resource is defined with the right name.

For you it means you must redefine the default resource as soon as you
define another one of the same type.

Side note: for prod it is more than highly recommanded to do that since the
default executor service can be synchronous or highly parallel, there is
nothing required in the spec so better to take the control of it.

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>
Post by clemensx
Hi,
we have problems using ManagedExecutorService resources in tomee 7.0.4
Using default ManagedExecutorService works fine, but if we try to define a
new pool with more threads we cannot access the service
<Resource id="FooManagedExecutorService" type="ManagedExecutorService">
Core = 40
Max = 50
KeepAlive = 5 s
Queue = 150
ThreadFactory =
org.apache.openejb.threads.impl.ManagedThreadFactoryImpl
Lazy = true
</Resource>
But then we cannot even get the default service injected in our stateful
@Resource(name="java:comp/DefaultManagedExecutorService")
private ManagedExecutorService execService;
will yield a null execService.
@Resource(name="FooManagedExecutorService")
private ManagedExecutorService execService;
same with trying to access our own resource.
Getting the reference programmatically via
execService = (ManagedExecutorService)
sessionContext.lookup(“openejb:Resource/FooManagedExecutorService”);
also gives null.
[CONTAINER] OpenEJB.startup.config INFO Auto-linking resource-ref
'openejb/Resource/ROOT/FooManagedExecutorService' in bean ProductDao to
Resource(id=FooManagedExecutorService)
3 times this info (no idea why the container is creating the resource 3
[CONTAINER] OpenEJB.startup.service INFO Creating
Resource(id=ROOT/FooManagedExecutorService,
aliases=FooManagedExecutorService)
[CONTAINER] OpenEJB.startup.config INFO Configuring
Service(id=ROOT/FooManagedExecutorService, type=Resource,
provider-id=Default Executor Service)
Thanks for any ideas/workarounds
clemens
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
clemensx
2018-07-16 13:57:33 UTC
Permalink
Many thanks for the fast and detailed answer!

Do I understand correctly that I can simply use the default name in the
resource.xml to extend the thread pool and should be able to use it
everywhere I used to access the default service with default settings?
@Resource(name="java:comp/DefaultManagedExecutorService"

That would be perfectly fitting to our needs.

Thanks!



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Romain Manni-Bucau
2018-07-16 14:06:01 UTC
Permalink
yes, note that "name" doesn't need "java", the namespace is a "lookup"
thing.

personally I would recommand you to stay away from default resources since
you have no idea how it will behave at runtime and I would just ensure to
name correctly each resource I use.

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>
Post by clemensx
Many thanks for the fast and detailed answer!
Do I understand correctly that I can simply use the default name in the
resource.xml to extend the thread pool and should be able to use it
everywhere I used to access the default service with default settings?
@Resource(name="java:comp/DefaultManagedExecutorService"
That would be perfectly fitting to our needs.
Thanks!
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Loading...