I'm reading the netty source code, and come across a synchronized
on formal parameter.
AbstractBootstrap(AbstractBootstrap<B, C> bootstrap) {
localAddress = bootstrap.localAddress;
synchronized (bootstrap.options) {
options.putAll(bootstrap.options);
}
}
localAddress
is not synchronized
because it's declared as volatile, any change to it is visable to other thread.
But I don't understand to synchronized
on a formal parameter bootstrap
.
bootstrap
is a formal parameter, every thread has it's own copy.
synchronized
on it only effect it's own thread? Is this opinion correct?
synchronized (bootstrap.options)
is to prevent bootstrap.options
to be modified outsides this class or to prevent this.options
to be modified by other thread?