I'm kind of confused here -
class A extends Thread {
public void run() {
synchronized (...) {
}
}
}
what may be the use of having a synchronized block in a thread's run
method ? I was under
the impression, that only one thread will access the run method i,e the
current running thread.
-t
BartCr - 13 Dec 2005 14:49 GMT
You can have multiple A's all running at the same time, synchronizing
on a shared object. That way only one of all A threads will execute the
code in the block at the same time.
A use for this might be where multiple threads append to the same file
from that run method. This way it is assured that the written data will
not end mixed up.
Bart