aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes deadlock pointer - need verification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "deadlock pointer - need verification " Watch "deadlock pointer - need verification " New topic
Author

deadlock pointer - need verification

Ken Boyd
Ranch Hand

Joined: Dec 10, 2003
Posts: 329
I have done many test on Data.java class and one of most important one is multiple threads (50 threads x 1000 times) trying to book one record. At the end of the test number on incremental field was 50,000.

In nutshell


T1 trying to book record 10 times 1000
T2 trying to book record 10 times 1000
|
|
|
T50 trying to book record 10 times 1000

end result in record 10 I found hotel name i.e. incremental field shows 50,000 number.

Now main question is my UI allow only one record to select/book per thread/client. Is there any possibilities tester will fire programmer where one thread try to book more then one record i.e.

trying to book record 10
T1
trying to book record 20

trying to book record 20
T2
trying to book record 10


Now in that case I found deadlock in Data.java since T1 try for 20 and T2 try for 10 and both are locked.

My question is I don't allow multiple room booking from UI and don't such thing in instruction. So is it safe to document saying current pilot program doesn't allow multiple room booking for one client (real world corporate client do it often) but production system can handle such thing and it is out of scope of assignment or future enhancement.

Please comment or I am heading towards famous 44/80 on locking or 0/80.

Thanks
[ May 08, 2007: Message edited by: Ken Boyd ]

SCJP, SCWCD, SCBCD, SCJD, BB Java2 and JSP1.1
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Ken Boyd:
I have done many test on Data.java class and one of most important one is multiple threads (50 threads x 1000 times) trying to book one record. At the end of the test number on incremental field was 50,000.

In nutshell


Now in that case I found deadlock in Data.java since T1 try for 20 and T2 try for 10 and both are locked.

My question is I don't allow multiple room booking from UI and don't such thing in instruction. So is it safe to document saying current pilot program doesn't allow multiple room booking for one client (real world corporate client do it often) but production system can handle such thing and it is out of scope of assignment or future enhancement.

Please comment or I am heading towards famous 44/80 on locking or 0/80.

Thanks

[ May 08, 2007: Message edited by: Ken Boyd ]


I took a few days to think about this one. This is an interesting question and it is not mentioned in the specification.

I would very much doubt that this would be a test of the examiners as this is very bad practice which would be mentioned by any basic locking tutorial. Allowing multiple random locks to be aquired by a thread without using them first is the programmingequivelant of playing russian roulette, ie you will get burned eventually.

If this was a test it would be a most unfair way of breaking the locking mechanism, in much the same way that one could also break the locking mechanism by locking every record with a single thread and never releasing them. This would not be bad design of the data class but rather bad use of it.

Multiple room booking is possible but only if the locks are aquired and released in sequence. In my project for example to book multiple records you would call the book method multiple times. Say for example book(10) book(20). the sequence of events would be lock(10) update(10) unlock(10)lock(20) update(20) unlock(20). You can safely assume that that any comercial systems that allows mulltiple bookings also follow this pattern.

I would not worry about this senario for I highly doubt that this is a test the examiner runs, if so it is a very lazy and unfair way of breaking the code. Also I can't remember ever seeing anyone only allowing one lock per client in their project.

Hope this helps,
Mark


SCJP<br />SCJD
Ken Boyd
Ranch Hand

Joined: Dec 10, 2003
Posts: 329
Mark thanks a lot for your reply.

Couple of threads where I explain situation in detail

http://www.coderanch.com/forums/

In above thread scroll down to 2-3 replies and you will see my detail explanation with code.

one more

http://www.coderanch.com/t/188740/java-developer-SCJD/certification/Testing-Tool-Data-Class

my reply in above thread explain the same problem mention in this thread with actual testing code.


Your input to above threads will be of great help.

You can reply in each thread or summarize here as I am watching recent threads.

Thanks for staying around after passing exam.
Ken
[ May 11, 2007: Message edited by: Ken Boyd ]
Ken Boyd
Ranch Hand

Joined: Dec 10, 2003
Posts: 329
Originally posted by Mark Smyth:


Multiple room booking is possible but only if the locks are aquired and released in sequence. In my project for example to book multiple records you would call the book method multiple times. Say for example book(10) book(20). the sequence of events would be lock(10) update(10) unlock(10)lock(20) update(20) unlock(20). You can safely assume that that any comercial systems that allows mulltiple bookings also follow this pattern.

Hope this helps,
Mark


Yes my data class works perfectly fine with the test you mention where I fire random record number from 1-30 and ask 20 threads to update records 100 times and end results everybody get chance to update and update field shows number 2000.

Now what if customer representative selects 4 records at once (not possible via GUI) but tester might try to do without releasing locks

e.g.

update(10);
update(11);
update(12);
update(13);
unlock(10);
unlock(11);
unlock(12);
unlock(13);

if another thread try to run like that we have nothing else but deadlock. Hope tester won't do it since he just forcing deadlock. I mean you can break any system by doing such thing.

Thanks for your input,
Ken
Lucy Hummel
Ranch Hand

Joined: Apr 07, 2005
Posts: 232
Hi Ken,

In my opinion the unlock should look like


update(10);
update(11);
update(12);
update(13);
unlock(13);
unlock(12);
unlock(11);
unlock(10);

Furthermore, I agree that it sould be quite okay to allow the GUI a single booking and put the choices.txt some explaination that it was not requested to allow multiple booking.


----------------------------------<br />| SCJP, SCWCD, SCBCD, SCEA, SCJD |<br />----------------------------------
Ken Boyd
Ranch Hand

Joined: Dec 10, 2003
Posts: 329
Originally posted by Hummel Lucy:
Hi Ken,

In my opinion the unlock should look like


update(10);
update(11);
update(12);
update(13);
unlock(13);
unlock(12);
unlock(11);
unlock(10);

Furthermore, I agree that it sould be quite okay to allow the GUI a single booking and put the choices.txt some explaination that it was not requested to allow multiple booking.


Thanks for your reply Hummel. Yeah I will document about single record booking via GUI in choice.txt.

Now above multiple locking will create deadlock since other threads try to update same records but it has to wait forever to since thread 1 has not called unlock on acquired records.

I know what I am testing isn't the way to do it but want to see what other ranchers think about it. (Mark was right in his description).

Thanks,
Ken
 
 
subject: deadlock pointer - need verification
 
Similar Threads
multiple bookings
Passed !!!!
Will this locking mechanism be allowed?
Take this Testing Tool for Data Class
Question on deadlock