?
Solved

EJB transaction logic with locking

Posted on 2001-06-27
6
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 6230702
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
ID: 6234108
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
ID: 6234798
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:sabaus
ID: 6236675
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
ID: 7616537
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
ID: 7639838
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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