If there is a deadlock, the code will hang forever, right?
In my case, since one thread tries to create same record again and again and another thread takes a random record number for modification, the test cases are bound to throw exception. So I simply swallowed them (not completely : I just did printStackTrace) and proceeded with testing.
Worst case scenario in my case was the loop counter as 2000 (since that created 10000 threads, my machine started crying and I stopped increasing counter at 2000).
Below are the results:
1) The code did not hang (due to my poor machine, it took over a minute to complete, but it did finish all the task)
2) Only exceptions thrown were RCNF(record not found) and DPK(duplicate key)
So I guess I can conclude that my DB operations are deadlock free, right?
Do you reuse deleted entries? If you don't, increasing counter has no added value at all and does not guarantee your code is thread safe. If you do, increasing counter will result in more threads competing for the lock of the same record and you could assume your code is thread safe.
Well, here is what interface comments say:
create : Creates a new record in the database (possibly reusing a deleted entry)
delete : Deletes a record, making the record number and associated disk storage available for reuse
Currently I'm not reusing deleted records since it is not a 'must' requirement
reusing deleted entries is not a "must" requirement, so you don't have to do that if you don't want to. - Roel
This will decrease the complexity and possible deadlock situations. If I don't go for reusing deleted records, would I be loosing marks? (I don't think it would be automatic failure, right? and at least I can expect full marks on locking )
If I follow this approach (not reusing deleted records), then I guess this is the time I should concentrate on RMI and GUI What say?
Like I already said: reusing deleted entries is not a must requirement, so you won't fail for not implementing it (nor will you lose points).
If you don't reuse record numbers using Roberto's Data class test with a counter set to 2000 has no added value at all (like mentioned in my previous post). Just running the program 2000 times with a counter set to 1 will give you more certainty about your code running without deadlock than running it once with a counter set to 2000.