File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes testing locks. 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 "testing locks." Watch "testing locks." New topic

testing locks.

Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
I am trying to test my locks. I have a test class that spawns a few threads. Each thread represents a client which is booking the same flight. The intention is to have multiple clients book the same flight at the same time so that I know if my locking and unlocking algorithm is working or not.

The problem is, on the client side I have the thread name with the output, so I know which client is doing what. But on the server side, I am not able to associate the clients with their respective threads on the server.
Any ideas how I can go about this?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11776

Hi Prakash,
Depending on how readable you want your output to be, you have some choices:
Within the thread, if you simply do a System.out.print(this) you should get at least some sort of unique identifier (possibly the hashcode for the thread), and possibly a whole lot of debugging information as well.

Or, overide the constructor (you are doing that anyway for your tests), and pass in a unique identifier:

You can even override the toString() method to make it nicer:

Does any of this help? If not please give more details of what you are trying to do.
Regards, Andrew

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
Probably, I wasn't too clear about my question. Let me re-ask this question. On the clientside when i run my threadtest class to test my locks I get the following output

On the server though, I get this

On the client I am clear about the thread name. But, on the server I am not sure which thread is locking and which thread is unlocking. Like, on the server side it says .
"The record number that is about to be locked is 1
Somebody is accessing this record, Please wait!
Just about to enter the unlock for record no 1"
It is not clear to me which thread does this corrrespond to...
I am going to try just doing
and see if things are clear on the server side. I think my question did get answered, though. I was just trying to make sure I had explained the problem well.:-)
[ April 16, 2003: Message edited by: Prakash Krishnamurthy ]
I agree. Here's the link:
subject: testing locks.
jQuery in Action, 3rd edition