GeeCON Prague 2014*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Using Roberto's tests for Data class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using Roberto Watch "Using Roberto New topic
Author

Using Roberto's tests for Data class

Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

Hi,

Today I ran Roberto's tests with my Data class.

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?


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5299
    
  13

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.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

Do you reuse deleted entries?


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?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5299
    
  13

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.
 
GeeCON Prague 2014
 
subject: Using Roberto's tests for Data class