0

I am using a CDI bean with conversation scope. I start a new conversation in a action method of my bean like this:

    if (conversation.isTransient()) {
        conversation.begin();
        logger.fine("start new conversation, id=" + conversation.getId());
    }

Now I recognized, that the IDs given by CDI are simple small numbers like '1' or '2' and so on. I was able, after some testing, to start different browser sessions which got at the end the same ID. So both browsers claim the id '1' for example. And this results in a conflict during the conversation.

I wonder if this behavior is normal (I am running in Wildfly)?

Should I begin my conversation by giving a generated unique id by myself?

    if (conversation.isTransient()) {
        conversation.begin(UUID.randomUUID().toString());
        logger.fine("start new conversation, id=" + conversation.getId());
    }

Update: As Siliarus comment, the ID is unique in the browser session. My own observation of a conflict in two different browser sessions, using the same CID, was wrong. There is no need to create a unique id by myself.

Ralph
  • 4,500
  • 9
  • 48
  • 87
  • Please elaborate on "And this results in a conflict during the conversation.". Creating a different browser session will trigger a new session within CDI. So you might end up having same conversation IDs but each belonging to a different session (assuming you are keeping both sessions alive then). That should not cause conflicts I think. It is just a first thought coming to me though. – Siliarus Oct 03 '16 at 11:13
  • Yes - you are right. I figured out that the id is unique in the session and it was my fault to think this would be a problem. – Ralph Oct 07 '16 at 20:24

1 Answers1

0

As Siliarus comment, the ID might be the same in the browser URL, but the ID is unique inside a session. So there is no conflict and it is not necessary to generate a unique id manually.

Ralph
  • 4,500
  • 9
  • 48
  • 87