• Post Reply Bookmark Topic Watch Topic
  • New Topic

Asynchronous persistence problem

Vitaly Komashilov
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have an issue that I can’t overcome.
I’m creating some kind of simulation system based on Message Driven Beans (MDB).

I have a set of Entity beans with underlying database structure. Also I have couple of Session beans that implement business logic of the system and manage entities via persistence context.
These beans are tested and seems have no bugs.

Main workflow of system is based on infinite loop created using Timer Service.
Every X seconds special session bean checks is there any data to be processed (simulated). It asks business logic bean for a list of items. There is quite complicated persistence query (JPQL) that returns needed items. Code is similar to this:

If any item is found, then item’s state is set to “Busy” (also via business logic bean) and it is sent to MDB queue for processing.

Queue is processed by special processor bean (MDB), which does main work (simulates all needed data) and finally sets status of item back to “Normal” (again, using business logic bean).

All beans are deployed within single EJB module. There is very light GUI for starting overall simulation process deployed as WEB application on the same server.

So far everything is working as it should and my goal is achieved: data is simulated.

But when I try to increase load to the system (by decreasing X time for the infinite loop) it starts act a little strange.
It sometimes “forgets” to set item’s state back to “Normal” and overall process hangs and waits for an item that is not busy. I have done some trace over called methods and found out that function for setting item’s state is called (!) but results does not achieve database (!).
The code of function for setting the state of item:

Item is an Entity, and its InProcess field is mapped to column in database. By calling following I set item state to “Busy” (called from infinite loop):

and to the “Normal” (called from MDB when it finishes simulation):

As I understand, em.merge() is not working as it should.
em.flush() does not helps too.
Most interesting is that “skipped” items every time is different (acts like random).
Is there any limitation in accessing the same persistence context from different types of beans?
From stateless session bean (within infinite loop) state is always set correctly, but from MDB it sometimes does not.
I was thinking about concurrent access to the same item from multiple beans at the same time, but it is impossible, because item’s state is set to busy before sending it to queue. Also database logs show that final update for normal state is not received. Transactions are not used (only default CMP).

May be someone have an idea where could I dig for solution?


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!