I am calling rabbitMQ client (and not server) from inside my Java code running in Glassfish V4.0 (build 89) container to connect to rabbitmq server on another machine. As per rabbitmq client document, we should supply a ManagedThreadFactory instance to rabbitmq connection for creating threads.
I tried injecting DefaultManagedThreadFactory using
ctx.lookup("java:comp/DefaultManagedThreadFactory")
That failed with
Lookup failed for 'java:comp/DefaultManagedThreadFactory' in SerialContext...
Trying @Resource(lookup="concurrent/__DefaultManagedThreadFactory") results in NPE.
I am not heavy into java EE and I am using this container just as a frontend for my jersey web services. Clearly I need to do something more/different. However I have been not able to locate much apart from
http://javahowto.blogspot.in/2011/02/how-to-create-and-look-up-thread-pool.html
Can any Java EE expert tell me the right Voodoo incantations to make this work?
Update-1
@Resource(name = "concurrent/__defaultManagedThreadFactory")
ManagedThreadFactory threadFactory;
// set on rabbitmq connection Factory
factory.setThreadFactory(threadFactory);
java.lang.NullPointerException
at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1312)
at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1233)
at java.util.concurrent.Executors.newFixedThreadPool(Executors.java:114)
at com.rabbitmq.client.impl.ConsumerWorkService.<init>(ConsumerWorkService.java:36)
Update-2
axel - there is nothing special about my case. Just trying a rabbitmq java client inside GFV4 is what I am looking at. so to reproduce the issues
- You need to run rabbitmq server
- connect to rabbitmq server using client code that is part of war deployed on GF
- as per rabbitmq client API guide (https://www.rabbitmq.com/api-guide.html) @see Custom Thread Factory section. They are delegating thread instantiation to the container.
- rabbitmq java client code is on Github
I can see ManagedThreadFactory name from GF Admin console so it should be there.
update-3
The Managed Thread Factory and Managed executor service can be located using JNDI. However the same resources cannot be injected into my code that uses Jersey web services. The resource injection works with a simple servlet example (e.g. java EE7 example on Github)
is this due to some interplay of jersey/Hk2/CDI/weld etc.? I am looking for an authorative answer to why I cannot make resource injection work?