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
Solved

EJB transaction logic with locking

Posted on 2001-06-27
6
176 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 114
how to add new optional parameter to JSP 1 49
eclipse apache tomcat admin console 52 119
ejb stateless example 2 18
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

790 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