Waiting for calculation...
Waiting for calculation...
Waiting for calculation...
Total is: 4950
Total is: 4950
Total is: 4950
Waiting for calculation...
Waiting for calculation...
Total is: 4950
Total is: 4950
Waiting for calculation...
Waiting for calculation...
Total is: 4950
Waiting for calculation...
Waiting for calculation...
SCJP 5.0, SCJD URLyBird 1.3.3, OCMJEA 5 (SCEA) Factory Homes
Regards, Siphiwe Madi
[SCJP, SCWCD, __] Next ... scjwsd
17.8.1
.
.
.
# A notify action being performed on m in which t is selected for removal from the wait set.
# A notifyAll action being performed on m.
# An interrupt action being performed on t.
# If this is a timed wait, an internal action removing t from m's wait set that occurs after at least millisecs milliseconds plus nanosecs nanoseconds elapse since the beginning of this wait action.
# An internal action by the implementation. Implementations are permitted, although not encouraged, to perform "spurious wake-ups" -- to remove threads from wait sets and thus enable resumption without explicit instructions to do so. Notice that this provision necessitates the Java coding practice of using wait only within loops that terminate only when some logical condition that the thread is waiting for holds.
SCJP 5.0, SCJD URLyBird 1.3.3, OCMJEA 5 (SCEA) Factory Homes
Originally posted by Siphiwe Madi:
Hi Vishwa,
Next, calculator.start() is called therefore the Thread "Calculator" acquires the lock released by c.wait() above,
it executes it's run() method and releases the lock.
SCJP 5.0, SCJD URLyBird 1.3.3, OCMJEA 5 (SCEA) Factory Homes
I think the new Reader("calculator").start() Thread lock is different from calculator.start() lock . Am i correct ?
Regards, Siphiwe Madi
[SCJP, SCWCD, __] Next ... scjwsd
What is the result of trying to compile and run this program?
A. It fails to compile because the IllegalMonitorStateException of wait() is not dealt
with in line 7.
B. 1 2 3
C. 1 3
D. 1 2
E. At runtime, it throws an IllegalMonitorStateException when trying to wait.
F. It will fail to compile because it has to be synchronized on the this object.
Answer:
D is correct. 1 and 2 will be printed, but there will be no return from the wait call
because
no other thread will notify the main thread, so 3 will never be printed. It's frozen at line
7.
SCJP 5.0, SCJD URLyBird 1.3.3, OCMJEA 5 (SCEA) Factory Homes
Something empties Calculator's waiting set, what it is?
Regards, Siphiwe Madi
[SCJP, SCWCD, __] Next ... scjwsd
Consider Paul's rocket mass heater. |