• Post Reply Bookmark Topic Watch Topic
  • New Topic

Ejb Threads use condition

 
Avianu Sud
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a EJB method that does a lot of processing, and reads and manipulates same value from the database.

There is a high chance of concurrent access and data collision on this method.

In a multi-threaded environment, I would put the method's body as "sync", so only 1 thread can access the method at a time.

What is the option in a EJB for the same.

Additionally, Can I block only a small segment of the Code in a EJB method?

Thanks in Advance,
Avi
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Avi,

As a rule of thumb remember that you neither need to synchronize the business methods of your ejbs nor any block of code within these methods. There is no reason to synchronize them, since bean instances are single threaded. Hence the concurrent access problem usually would be raised at the database level rather than ejb level (good design can avoid any of these problems). All you have to do is to review your transactions and redesign them if necessary in order to satisfy your system requirements. Always remember that ejbs does their work within a transaction scope and rather than being concerned about the data access for each method, you should analyze this problem from a transaction perspective. Finally you can avoid data concurrency by setting the appropriate transaction isolation level.
Regards.
 
Avianu Sud
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very helpful. Thanks.
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're very welcome Avianu
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!