last day (15 days later) » 

10:42 PM
2
A: Arguments overridden in managed callable tasks in Java EE

LppEddThis is perfectly normal. A @Stateless bean is created in multiple instances, depending on your server pool configuration.So the same instance is re-used from the pool. Per definition a @Stateless bean cannot maintain a state. Use a @Stateful bean instead.

 
So how to fix this to use different instances and receive in each task a different value argument?
 
@ps0604 see updated answer.
 
I changed bean MyTask from @Stateless to @Stateful and I get Caused by: javax.ejb.ConcurrentAccessTimeoutException: WFLYEJB0228: EJB 3.1 FR 4.3.14.1 concurrent access timeout on MyTask - could not obtain lock within 5000 MILLISECONDS (thrown in invokeAll)
 
@ps0604 debug and check if the returned instances are the same or not (might also be returned a proxy)
 
please see update in the question, they seem to be different
 
10:42 PM
@ps0604 now set a breakpoint inside setValue (set the breakpoint to stop all the threads) and see if it arrives there
 
The breakpoint inside setValue stops twice (one for each task) but that happens before invokeAll where the exception is thrown
 
@ps0604 when the breakpoints stop, you should be able to see which instance you're inside (like you did before). Check if it's the same. If they're different, the problem is caused by something else
 
They are different. I tried something else: I commented out adding a second task, and I get the same error
 
@ps0604 I never tackled such exception. I'll try to look around for an explanation. But as you can see the instances are different now.
 
Ok, I'll accept your answer because the instances are different, but I still have the problem to pass the argument to the task :)
 
10:42 PM
@ps0604 This is somehow strange. I mean, why would it lock for more than 5 seconds? You only return a String. Or did you omit something in the question?
And why would it lock in the first place.
 
The only thing that in the question is different is that the Test class is a @Stateless bean
 
@ps0604 look at this. Seems the same usecase access.redhat.com/solutions/1341983 I think you need to change strategy here.
Btw, an EJB container already handle concurrent requests, so why are you using an executor?
 
The intent is to run many tasks in parallel, managed by the container and receive the responses. Btw, all these tasks are read-only, I don't need any type of transactions to manage concurrency.
 
@ps0604 does this task really need to be an EJB bean? There is a lot of overhead using EJBs
 
It has to be as the container needs to be aware of the thread. That's why I'm using ManagedExecutorService
 
10:42 PM
@ps0604 Sure, but you can submit a plain Java object to the ManagedExecutorService. There is no need for it to be an EJB bean.
 
The task would have injected EJBs, can it be a POJO?
 
@ps0604 not really a pojo in that case, but you can leverage CDI, using the Inject annotation, or the EJB annotation if you need more control, to inject EJBs
 
I submitted a plain Java object to the executor, and it worked. But when I try to inject a bean in this Java object with @Inject, I cannot use it because it's null.
 
@ps0604 try with the EJB annotation. There are multiple factors as to why the instance is null.
 
Didn't work with @EJB either, any other ideas? thanks
 
10:42 PM
@ps0604 wait, how are you getting this class?
 
It finally worked with JNDI lookup
 
@ps0604 that's good! The only drawback is that the lookup is manual. I remember years ago when I worked with EJB 2.1, what a mess.
 

last day (15 days later) »