1 Reply Latest reply on May 18, 2007 6:39 PM by wpernath

    Concurent creating problem

    johnmm1997


      I'm programming a system where people can submit "tasks" for evaluating.

      When a person submit a task, the request go into a JMS queue, and later on a MDB is processing the task.

      Task is an entity.
      If there is no task with that id, i need to create it first (long operation)

      The problem-
      If there are 2 tasks request with the same id, and the id isnt in the db yet, the task is created twice (sometimes)

      As a javaSE programmer, i thought about creating a singleton with concurentHashMap to flag which id's being created, but i learn that you cannot use singeltons in javaEE (mostly due to clustering scaling i guess)

      so, what is the solution?

        • 1. Re: Concurent creating problem
          wpernath

          Hi,

          I was having quite the same problem some years ago. This is because jboss is using more threads when it is on load (i.e. if there are more than one item in the queue - you can test this really easily if you simulate heavy load).

          I think you should separate the creation of the entities. If your MDB realizes the task does not exist and must be created, you should put the task into another queue and wait until it exists.

          The second MDB which creates the tasks should search for a mark saying "Creating task xyz" and only if this mark does not exist, the task should be created. Or in short form:

          1. Is task xyz is currently created?
          2a. No, try to find task with this id. If not found, create mark, create task and delete mark, else skip
          2b. Yes, skip

          HTH,
          Wanja