0

I am injecting multiple @ConversationScoped beans in one @ViewScoped bean and this has caused a lot of Conversation Locked issues.

To rectify this issue, in all the @ConversationScoped bean, I put lines of code to end the existing conversations before starting a new one.

As you can see when going into begin(), I will end all the previous conversations before starting a new one.

public void begin() {
   if (conversation != null
       && !conversation.isTransient()) {
           end();
   }

   if (conversation.isTransient()) {
      conversation.begin();
   }
}

Is this the proper way to do it ? Will this cause problems ?

  • Can you expand on what you mean by `Conversation Locked issues`? – Siliarus Aug 05 '19 at 11:21
  • So basically when I navigate into the ViewScoped bean injecting multiple ConversationScoped beans, I get this error "WELD-000315: Failed to acquire conversation lock in 1,000 ms for Conversation with id" and it will navigate me to the index page – Nik Mohamad Lokman Aug 06 '19 at 03:08
  • Hmm, that sounds more like a race condition issue on creating a long running conversation? Could be a Weld bug, if you have a shareable reproducer create a JIRA issue for Weld and attach it - https://issues.jboss.org/projects/WELD – Siliarus Aug 06 '19 at 08:02
  • Will try to, is it fine if I proceed with the approach above where i end conversation before starting a new one ? The issue is resolved after i did so, but i am not sure if there will be other issues when i do so – Nik Mohamad Lokman Aug 07 '19 at 01:19
  • Hmm, in theory that should make no change as `begin()` called on an already active conversation should lead to `IllegalStateException` (which wasn't your case before you added `end()`). But it seems to somehow bypass the race condition maybe? Hard to say how reliable that would be though... – Siliarus Aug 07 '19 at 07:10
  • I'll take that as a safe until proven otherwise – Nik Mohamad Lokman Aug 07 '19 at 08:18

0 Answers0