【发布时间】:2009-12-30 21:40:05
【问题描述】:
这里同步的意义何在?
为什么不直接使用mConnectedThread.write(out)?
代码 sn-p 来自 Android 的 BluetoothChat 示例(found here)
/**
* Write to the ConnectedThread in an unsynchronized manner
* @param out The bytes to write
* @see ConnectedThread#write(byte[])
*/
public void write(byte[] out) {
// Create temporary object
ConnectedThread r;
// Synchronize a copy of the ConnectedThread
synchronized (this) {
if (mState != STATE_CONNECTED) return;
r = mConnectedThread;
}
// Perform the write unsynchronized
r.write(out);
}
【问题讨论】:
标签: java android synchronization