• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using Roberto's tests for Data class

 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic