This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

forced to lock and then read

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Randchers,

I�ve finished my B&S coding, and now I am doing Data.class testing for updateRecord() and deleteRecord(), but found the lockRecord method is not thread�safe. Here are the codes:

where data is an instance of Data.class and bookManager is to logically lock (place an entry in a WeakHashMap) a record which prior to deleting or updating.
When multiple threads, delete and update together, acquire same record, a delete thread can lock a record that has been deleted. Say:
a delete thread and a update thread both can find the same record, now the update thread go asleep and the delete record carries on and finally removes the record. Afterward, a update record wakes up and then successfully locks up an unexisting record.

To fix it, an alternative is to lock record first regardless of it's existence. Here is the method

Is it odd to handle securityException exception by rethrow a RecordNotFoundException exception with "Cookie held by another..." ? Or other solutions can anyone draw my attention?

Thanks very much
 
Bob Stone
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made mistake, the alternative should be :

 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic