This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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
Andrew: 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 ]