• 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

Data class test for B&S - do I have a problem?

 
Ranch Hand
Posts: 92
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

firstly big thanks to Roberto Perillo for the excellent DataClassTest. I've slightly modified this for B&S but I have two queries;

1) Occasionally I get a RNFE when the DeletingRecord1Thread gets executed before the UpdatingRecord1Thread. This seems correct to me, is this what others have found?

2) If I up the loop counter to anything more than 1 I will get DuplicateKeyExceptions thrown - which I would expect because I'm re-creating the same record over and over again in CreatingRecordThread. Again this seems correct to me, what have others found? I do get into deadlock in this situation but I can't assess what this means when so many other DKEs are happening.

Other than that, I suppose I'm at the horrible stage of thinking that the Data class is complete, but scared of automatic failure due to some unforseen locking error on my part...

Regards,

John

PS

I'll happily post the updated test code if an admin can confirm I won't be breaking any rules by doing so. I think not, it's not part of the submission.
 
John McParland
Ranch Hand
Posts: 92
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Slight update;

I changed the CreatingRecordThread and UpdatingRandomRecordThread to generate records which have different database keys each time so as to avoid DuplicateKeyExceptions. Now I still have the problem with RecordNotFoundExceptions when I run the test 10 times. Here is the relevant output;

16 locked record #1 on DeletingRecord1Thread
16 trying to delete record #1 on DeletingRecord1Thread
38 updated record #23 on UpdatingRandomRecordThread
38 trying to unlock record #23 on UpdatingRandomRecordThread
16 deleted record #1 on DeletingRecord1Thread
16 trying to unlock record #1 on DeletingRecord1Thread
38 unlocked record #23 on UpdatingRandomRecordThread
16 unlocked record #1 on DeletingRecord1Thread
56 caught RecordNotFoundException for record #1 in DeleteingRecord1Thread
31 caught RecordNotFoundException for record #1 in DeleteingRecord1Thread
34 caught RecordNotFoundException while updating record #1 in UpdatingRecord1Thread
19 caught RecordNotFoundException while updating record #1 in UpdatingRecord1Thread
26 caught RecordNotFoundException for record #1 in DeleteingRecord1Thread
24 caught RecordNotFoundException while updating record #1 in UpdatingRecord1Thread
46 caught RecordNotFoundException for record #1 in DeleteingRecord1Thread
41 caught RecordNotFoundException for record #1 in DeleteingRecord1Thread
54 caught RecordNotFoundException while updating record #1 in UpdatingRecord1Thread
49 caught RecordNotFoundException while updating record #1 in UpdatingRecord1Thread
21 caught RecordNotFoundException for record #1 in DeleteingRecord1Thread
11 caught RecordNotFoundException for record #1 in DeleteingRecord1Thread
36 caught RecordNotFoundException for record #1 in DeleteingRecord1Thread
39 caught RecordNotFoundException while updating record #1 in UpdatingRecord1Thread
29 caught RecordNotFoundException while updating record #1 in UpdatingRecord1Thread
14 caught RecordNotFoundException while updating record #1 in UpdatingRecord1Thread
51 caught RecordNotFoundException for record #1 in DeleteingRecord1Thread

Notice 16 correclty locks, deletes then unlocks record 1. Afterwards numerous threads find they cannot update nor delete record one. This seems right to me, does it to anyone else?
 
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
Hi John,

1/ When a record is deleted, a thread should not gain the lock on that record again. So the lock-method should throw the RNFE, not the update/delete method

2/ When you have B&S you can throw a DKE, but your code should not deadlock of course when such exceptions are being thrown!

I'll happily post the updated test code if an admin can confirm I won't be breaking any rules by doing so. I think not, it's not part of the submission.

You won't break any rules, just go for it! I would add the updated code to the thread of the data class test (and not this one)

Kind regards,
Roel
 
John McParland
Ranch Hand
Posts: 92
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Roel,

yes it is the lock method that throws the RNFE, so maybe that area is working. Clearly I need to look at the times a DKE is thrown and ensure that it does not deadlock.

I'll post the code to that forum once I know both my Data class and the test class are working as they should be.

Thanks again,

John
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John McParland wrote:I'll post the code to that forum once I know both my Data class and the test class are working as they should be.



That will be appreciated, champion!
 
John McParland
Ranch Hand
Posts: 92
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I got it working (I hope!) I investigated where the exceptions were being thrown and in those cases, printed to the console that this is what happened. Sometimes I executed a check to see that the exception was expected (e.g. in UpdatingRandomRecordThread if it tried to update record 1 I might expect a RecordNotFoundException) and I haven't seen any unexpected exceptions or deadlock since.

One minor thing that's bugging me, my Data class follows the facade pattern, calling methods in my "Database" class. A lot of other folks needed to synchronized the Data class methods, I only did my Database methods. I guess the end result is the same (the threads gets the object lock on one object) but still...

The code is now on the other thread.

Regards,

John
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John McParland wrote:A lot of other folks needed to synchronized the Data class methods, I only did my Database methods. I guess the end result is the same (the threads gets the object lock on one object) but still...



I am one of these people. This is just to be sure that the Data class is Thread-safe. It's sort of hard to say without looking at the code, but I also think it's pretty much the same. If you didn't get deadlocks, then it a-ok!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic