Solved

EJB transaction logic with locking

Posted on 2001-06-27
6
173 Views
Last Modified: 2013-11-24
Hi,

I have 2 stateless container managed transaction beans called OrderSLB and ContractSLB and one CMP bean OrderEB wrapping around an order table.

The orderslb has a method called updateOrder() defined with a Required attribute. This method does the update on the order row be looking up the OrderEB bean by findByPrimaryKey() (...besides some other operation ...)

The second bean contract bean has a method called executeContract() been defined with Required attribute. This method does 3 things
1) Check for business validity.
2)updates a status field in the order table so looks up the orderEB to do the job
3) Inserts a record in the Contract table.

The ordereb has ben set with a repeatable read serializable transcation isolation

When 2 user do a simultaneous where one does an updateOrder() and one and executeContract() I want only one user to succeed and i should be able to give an error message to the other user.  

Now i get a number of outputs when i try to do the operations simultaneously. One of them is : the updateorders() happenes first, then the update of status on the executeContract(). (note this happens between the validity check and the change of status...) Businesswise this is a bad situation. How do i prevent this ? How do i implement locking so that i know when i start the trasaction for exceuteContract() the order will not be updated

Im using Weblogic 5.1 and Oracle 8.0.6

Saba

0
Comment
Question by:sabaus
6 Comments
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
Hacky answer, but couldn't you set a

  public static boolean flag = false ;

variable in your ContractSLB, and then set this to true when someone does an executeContract().

Then check this variable:

  if( ContractSLB.flag )
    return someError;

in your update order method...

Hmmm...might work...must be a better way of doing though...

Good Luck,

Tim.
0
 

Author Comment

by:sabaus
Comment Utility
Its crazy ... im talking here about stateless beans how can i be gauranteed that i will be given the same bean when i check in the updateorder() method. Moreover im talking here about millions of orders being exceuted... its impossible here to track some order and flag relationship

Saba
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
I'm talking about a static variable...

Also, I thought EntityBeans (which I guess you are using for the db Access) implemented locking, so you won;t get to events occuring at the same time?  I thought this was the whole point...  Basically Transaction based locking...

maybe I am crazy tho
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:sabaus
Comment Utility
Its crazy doing it this way. Why should I prevent someone from updating his order when someone else's order being executed? There has to be a way of being more specfic to an order so that we can achieve an order based locking.
0
 
LVL 5

Expert Comment

by:vemul
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points refunded
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now