Regards
Shri..
SCJP 5.0
SCJP 5.0 SCWCD 5.0
Regards
Shri..
SCJP 5.0
Shrinath M Aithal wrote:No dude, I too tried the same code, and its not "waiting" 10 seconds before printing y..
I am getting the output as "xy" fine, but not with 10 second gap..
did you get 10 second gap?
SCJP 5.0 SCWCD 5.0
Regards
Shri..
SCJP 5.0
Shrinath M Aithal wrote:super confusion now
why isn't it waiting in my system ? I tried running it on another system too, both not giving lag between x and y..
and I tried other programs with "wait()" command, no program is waiting on this command.. ???
why isn't wait working with my system?
SCJP 5.0 SCWCD 5.0
SCJP 5.0 SCWCD 5.0
avi sinha wrote:
since you haven't overridden run method here the thread t becomed dead as soon as it is started hence there is no lag.
Regards
Shri..
SCJP 5.0
Regards
Shri..
SCJP 5.0
Shrinath M Aithal wrote:
so you mean to say, "t" is a dead thread when we are calling t.wait(10000); ???
and you can acquire synchronization on a dead thread?
and one more thing .. just to bug avi sinha ---> how did you get lag the first time? and why???
and the code you posted above, is infinitely waiting even after printing x and y and is inside your run method forever..
SCJP 5.0 SCWCD 5.0
Shrinath M Aithal wrote:I think i found a proper way..
watch this :
that does the job exactly as required.. but is that mature way?
SCJP 5.0 SCWCD 5.0
If the wait were placed inside a synchronized(t)
block, then the answer would have been D.
Regards
Shri..
SCJP 5.0
avi sinha wrote:
the original code you posted in you first post & this code is entirely different.
wait method in the first code was being called by the main thread & here it is being called by the thread you ve created. & it is not allowing any other thread to execute because there is no any thread hence it is just waiting for 10 secs
avi sinha
Regards
Shri..
SCJP 5.0
Shrinath M Aithal wrote:so, does it suggest that the answer given in book is wrong? because it says
If the wait were placed inside a synchronized(t)
block, then the answer would have been D.
that didn't happen.. so it doesn't work as said?
>> about bugging Mr avi sinha :
I meant to ask you how you got the "10 second " lag the first time I agree with whatever you said about the thread taking different times to complete printing x and y on different executions.. But usually, its instantaneous.. and you getting proper 10 second lag, is that co incidence ?? ;)
lets drop it.. that'll not help with threads lets talk about the priority of this discussion " is the answer specified in k&b about option "D" wrong? "
SCJP 5.0 SCWCD 5.0
Oh. Hi guys! Look at this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|