Wozu dient diese Synchronisation?
Worum geht es hier bei der Synchronisation?
Warum nicht einfach nutzenmConnectedThread.write(out)
?
Das Code-Snippet stammt aus dem BluetoothChat-Beispiel für Android(hier gefunden)
/**
* 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);
}