Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Does this method live in Data? Why did you modify the lock() method signature?
Eliminate this temporary variable
Fowler's Refactoring
Why use an array?
The purpose of your code, apparently is to implement a database lock implementation on top of a record lock implementation ("locker") by progressively locking all records.
I think this is a mistake,
This is true. Shall I keep track of the new records been added, by calling the getRecordCount() every time I do locking? This would cost a few CPU cyles. Is it okay?# your "database lock" in place a client can successfully acquire record locks on any records that have been added after the lock(-1) started executing.
This deadlock would cause tragedies in my marks .I am not able to see any deadlock, becuase one client can lock any number of records, either 1 or complete lock. If it has locked complete, all others have to wait. Please help me understand where I made the possibility of deadlock error.# It is incredibly deadlock-prone. Any client which acquires more than one record lock at a time in any order other than ascending by record number can deadlock if a database lock is in progress.
# Your memory consumption is proportional to the number of records in the database, which is rarely a good idea with databases.
But Peter, isn't this a hard possibility to wait for everyone to stop locking for a database lock to proceed. This situation may not be in a working situation, because there will be a number of people locking/unlocking records. Our 'Full Databse lock' thread is also one among the competing thread, with equal priority. Is my thinking correct ?The easiest way to implement it without running into deadlock issues is to wait until there are no more outstanding locks, then impose the database lock.
I shall do this as you suggested.* You don't support interrupts and any attempt to interrupt database server threads is a fault condition. Rethrow InterruptedException wrapped inside a RuntimeException (e.g. a DatabaseInterruptedException extends RuntimeException).
That's one way to solve it, but it's less than ideal. In the past, I've seen plenty who did this and passed. On the other hand, Max mentioned a week or so ago that Sun intends to become stricter. Bottom line is, I'm not sure either way.Originally posted by Rajesh Rajesh:
It is part of the Data class. I did not get any other idea to identify the person who locks the record. I was told by members of this forum that it is not a bad idea for this way of identifying and changing the method signature.
In principle, yes; but unless I'm mistaken, in your removeFromArray method you are forced to create a new array and copy the old values into the new array. That negates any performance advantage you might've had.I presumed that using primitive values are easier for the JVM than Integer objects in a List or Set. Easier in terms of execution time.
That's not enough. Say that you did this, acquired record locks on every single record, and this call returned. It would still be possible to add a record and then acquire a lock on it, despite the fact that a database lock is in place.Shall I keep track of the new records been added, by calling the getRecordCount() every time I do locking?
Don't get me wrong. With the FBN client, there is no danger of deadlock, because no client gets more than one lock at a time. But Data is not an FBN database. A five-minute inspection of the code should convince you that Data is a fully generic, reusable database. You have to code for reuse. Unless the instructions have changed, this is stated in the instructions as well.This deadlock would cause tragedies in my marks.
Yes.Are you telling [that memory usage is proportional to #records] because I am using an array to store all the record numbers?
Before proceeding to lock a record, don't you need to know the bytes you are locking? Well, no, you don't. In the same way, you don't need to know the records you are locking if you just introduce a single flag that indicates whether a database lock is being held (and by whom). Of course, this lock can only be granted when there are no record locks, etc.Before proceeding to lock, don't we need to know what records we are locking? Hence I have used arrays. Another advantage of my code is that it can be modified very easily for locking specified number of records. For example a client can lock 4 to 15 records. These are advantages of using arrays.
Your thinking is correct, in principle. Yes, what I described basically means that record locks are given priority over database locks. Whether that is acceptable depends on what you think the database lock is for -- the instructions don't tell you, so it is up to you to come up with a theory and implement your design accordingly. I would just want to make the following two points.But Peter, isn't this a hard possibility to wait for everyone to stop locking for a database lock to proceed. This situation may not be in a working situation, because there will be a number of people locking/unlocking records. Our 'Full Databse lock' thread is also one among the competing thread, with equal priority. Is my thinking correct ?
I outlined four completely different alternatives, and you can probably put up a decent argument for every single one of them. Take your pick. The only point I was trying to make, really, is that this is not a matter of taste or chance but another one of those design decisions that you should consciously makeI shall do this as you suggested [re: interrupt handling]
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Seriously? That's what you're going with? I prefer this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|