-
1. Re: Periodic recovery thread in Java EE
mmusgrov Jun 22, 2015 9:30 AM (in response to gytis)Sounds like a useful change. You should be able to introduce a setter that takes a java.util.concurrent.ThreadFactory which defaults to Executors.defaultThreadFactory but in wildfly the transactions subsystem passes in the managed version (javax.enterprise.concurrent.ManagedThreadFactory)
-
2. Re: Periodic recovery thread in Java EE
tomjenkinson Jun 22, 2015 9:56 AM (in response to mmusgrov)I agree, I don't think is actually too invasive a change as the PeriodicRecovery class is internal. I have a small prototype that is actually very small:
-
3. Re: Periodic recovery thread in Java EE
tomjenkinson Jun 22, 2015 10:00 AM (in response to tomjenkinson)Misfire sorry!
The commit is this: PeriodicRecovery as Runnable · jbosstm/narayana@04ade78 · GitHub
As you can see, its not configurable atm but what Mike proposes should be possible. It does look like we would lose the ability to name the thread unless I am missing something in the API? This would not be ideal but the benefit of being able to resolve from JNDI in the JEE environment would outweigh it for me.
-
4. Re: Periodic recovery thread in Java EE
gytis Jun 22, 2015 10:04 AM (in response to gytis)I was hesitant on changing Thread to Runnable. But you're right, since it's internal class it shouldn't be a problem.
Thanks for the suggestions.
-
5. Re: Periodic recovery thread in Java EE
mmusgrov Jun 22, 2015 10:16 AM (in response to tomjenkinson)As you can see, its not configurable atm but what Mike proposes should be possible. It does look like we would lose the ability to name the thread unless I am missing something in the API?
We could still have named threads in the standalone case since we can provide our own ThreadFactory implementation that does the thread naming. But yes I agree that would not work when running inside an app server.
-
6. Re: Periodic recovery thread in Java EE
tomjenkinson Jun 22, 2015 10:50 AM (in response to mmusgrov)I don't think the API of threadfactory newThread provides a name param - unless we made a threadfactory that creates all threads with "Periodic Recovery" as the name? I am not too keen on that one but as you suggest it would keep the current behavior the closest - at least in standalone mode.
-
7. Re: Periodic recovery thread in Java EE
gytis Jun 22, 2015 10:52 AM (in response to mmusgrov)I think thread.setName() should work for that
-
8. Re: Periodic recovery thread in Java EE
tomjenkinson Jun 22, 2015 11:03 AM (in response to gytis)Great - seems like you have all the pieces of the puzzle then
-
9. Re: Periodic recovery thread in Java EE
marklittle Jun 22, 2015 1:23 PM (in response to gytis)Before changing anything could you please explain why this is "crucial for compensations implementation"?
-
10. Re: Periodic recovery thread in Java EE
gytis Jun 22, 2015 2:21 PM (in response to marklittle)Couple of things. Firstly, internally it uses BeansManager to instantiate compensations/confirmation/logging handler beans. To get the BeansManager instance it uses JNDI.
Also, since all handlers are implemented by the user, this would forbid them from using JNDI in their implementations too. Or they wouldn't work during recovery.
-
11. Re: Periodic recovery thread in Java EE
marklittle Jun 22, 2015 6:36 PM (in response to gytis)OK but I don't get how this has anything to do with the PeriodicRecovery Thread implementation. If we are going to make changes to code we need to make sure that we document the reasons as much as possible in case there are issues which come up later and people at that time need to know why we made such changes. I'm not making any comment on whether or why this specific change is needed, I'm talking purely about documenting the initial requirement that kicked off the discussion. You, Mike and Tom may know precisely what you meant, but it's not coming through in your responses so far.
-
12. Re: Periodic recovery thread in Java EE
mmusgrov Jun 23, 2015 4:43 AM (in response to marklittle)What about the other places where we manage thread creation ourselves (such as asynchronous synchronizations and 2PC end calls). Will these be similarly effected?
-
13. Re: Periodic recovery thread in Java EE
gytis Jun 23, 2015 4:47 AM (in response to marklittle)The problem is that PeriodicRecovery extends Thread class and is created with a new operator. In such case container doesn't know about such thread and cannot provide the correct context for it. Later on during the recovery I read log entry and try to recreate ParticipantImpl which fails with "javax.naming.NameNotFoundException: java:comp/env/BeanManager" (similarly as discussed in [1] and a few others).
Even if I would work around this somehow, similar problem would arise when calling user compensation/confirmation handler, if it uses JNDI to get its datasource.
[1] Unable to look up java:module/ JNDI entries from new thread in JBoss EAp 6 - Red Hat Customer Portal
-
14. Re: Periodic recovery thread in Java EE
gytis Jun 23, 2015 4:52 AM (in response to mmusgrov)Mike, I assume it should. But I guess JNDI isn't used there, thus nothing happened so far. It's probably not worth changing that, if nobody ever had an issue with synchronizations of 2PC.