Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

lock and deadlock

 
pramod karnani
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// Locks a record so that it can only be updated or deleted by this client.
// If the specified record is already locked, the current thread gives up
// the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;


does requirement say that should I handle deadlock ?

what I understood As per Specification I should not handle deadlock.
Am I correct ?

please reply
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says you should prevent it from happening!
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my specification is the same and i think roberto is right: if your app goes into deadlock, you won't get 80/80 for your locking

i want to use facade-pattern to my Data-class, so i have 2 helper-classes: one for database-access and manipulation, one for locking/unlocking records. but the lock-method has to throw a RNF-exception if recNo doesn't exist. So that implies that my LockingManager has to have access to my DataManager. Both classes will have locking mechanism, so it seems that this might lead to deadlock situation, because lockingmanager has to access datamanager (see if record exists) and datamanager has to access lockingmanager (to see if record that's get updated/deleted is locked) or do i miss something in my logic?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if your app goes into deadlock, you won't get 80/80 for your locking


Actually, if that happens, you'll get 0/80!
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

actually i don't know if the tester will run my code with the following:

DB database = new Data("database_file_name.db");
// database instance will pass to two thread.

thead 1:
@t1: database.lock(5);
@t2: database.lock(11);
@t3: ...

thread2:
@t1: database.lock(11);
@t2: database.lock(5);
@t3: ...

in this case my implementation will deadlock because i don't care for the deadlock to happen inside the implementation of the data class itself , but i consider it in the adapter that adapt the db instance.


so i will get 0/80 or 40/80 or

what you think guys ?

Best Regards.
Mohamed Sulibi
SCJP, SCJD in progress (from 1/8/2007 till now)
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohamed,


thead 1:
@t1: database.lock(5);
@t2: database.lock(11);
@t3: ...

thread2:
@t1: database.lock(11);
@t2: database.lock(5);
@t3: ...


In my humble opinion, by the time thread 1's @t2 starts locking record 11, thread 2's @t1 should have unlock record 11 in order to avoid deadlock. Depending on how you implement your Data class's locking after every read/write the flags to check if any record is locked should be false or 0.

From the end user if I don't get deadlock i give 80/80. If it hangs, I give you 0/80. The coding tells you how much points you would get.

I designed my locking mechanism using the Read/Write Lock design pattern. I also used the Critical Section design pattern to instantiate my Data class.

 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

sorry, mean:

thead 1:
@t1: database.lock(5);
@t2: [long work]
@t3: database.lock(11);
@t4: ...

thread2:
@t1: database.lock(11);
@t2: [long work]
@t3: database.lock(5);
@t4: ...



best regards.
mohamed darim.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic