我正在查看蓝牙聊天示例,但我不明白为什么在下面的代码中它在本地 ConnectedThread 对象的副本上同步。r & mConnectedThread 肯定指向同一个对象吗?
public synchronized void write(byte[] out)
{
// Create temporary object
ConnectedThread r;
// Synchronize a copy of the ConnectedThread
synchronized (this)
{
if (mState != ICommsService.STATE_CONNECTED)
return;
r = mConnectedThread;
}
// Perform the write unsynchronized
r.write(out);
}