Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

How to avoid race condition in gigaspaces read / write operations?

Hi All,

I have a class called CacheLandingPadNumber which has three states (AVAILABLE, IN_USE, DELETED). First time in the cache the state of the object is AVAILABLE (I will be storing these objects into memory while starting the application).

I have two methods (readOneAvailableLPNFromPool) one is for reading one AVAILABLE entry from memory (In memory data grid) and other method (updateObjectInMemory) will update the object into IN_USE state. If I ran load tests with more number of concurrent users. I am facing the race condition. (ie.,) two threads accessing the first method (readOneAvailableLPNFromPool) both are getting the same object from pool and updating its status.

I can use synchronize block in my code but this application is running in two different servers. So synchronize will not solve my problem. I have to lock the row from memory some how so that this race condition will not occur.

Please help me on this. I have attached the entire code.

Edited by: Gopinathan Mani on May 2, 2013 7:11 AM

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=4071]{quote}

asked 2013-05-01 21:00:15 -0500

get4gopim gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-05-01 21:06:01 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Hi Shay,

Thanks for your valuable inputs.

Both optimistic and pessimistic locking worked for this solution.

Change API is not worked.

get4gopim gravatar imageget4gopim ( 2013-05-03 00:33:28 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-05-01 21:00:15 -0500

Seen: 66 times

Last updated: May 01 '13