SCJP, SCJD
SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
That is true, but it is hard to have a real test for that service method, because it depends on the content of the data file and on the assumptions you make.Roberto Perillo wrote:Maybe there could be another Thread that also searches for rooms? What do you think?
javadoc of the join-method wrote:Waits for this thread to die.
Savas Aydin wrote:Do you have any guess about what can be the leak?
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Savas Aydin wrote:I just wanted to ensure bookRoom works correctly on multi-client environment.
Roel De Nijs wrote:
So what are you experiencing if you run the code as-is (with the thread.join();) which makes you (or your code) unhappy?
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane wrote:To get the main thread waiting for all the spawned off threads to finish, simply do this
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Martin Vanyavchich wrote:After a good look at the code I've realized that we're always booking room with record number 0.
Martin Vanyavchich wrote:Now the record number gets incremented, and rooms 0 trough 35 get booked.
Roel De Nijs wrote:
If you are always booking record number 0 (comment line 62), you wouldn't see 35 'booked no room' messages, because one client should have booked room 0, all other threads shouldn't be able to book the room.
Roel De Nijs wrote:
So your original output is not what you should expect. And your "fix" is also questionable: changing it into a class variable which will be modified by a bunch of threads (in a non thread-safe way). I don't see how this could fix your initial problem.
Roel De Nijs wrote:
Martin Vanyavchich wrote:Now the record number gets incremented, and rooms 0 trough 35 get booked.
That's also weird. I don't think your database file contains 35 records at the start.
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Martin Vanyavchich wrote:Should probably use an Integer and synchronize on it. I thought that we're trying to start 35 threads, that will try to book rooms 1 trough 35, and some will fail at it. That's why I made it into a class variable.
Martin Vanyavchich wrote:thank you for the test class
Fatih Onur wrote:I would like to submit a bug fix regarding the testing code(line:62) for people who might be get mad to fix their own production code as I did.
Consider Paul's rocket mass heater. |