org.xsocket
Annotation Type Synchronized
@Target(value=TYPE)
@Retention(value=RUNTIME)
public @interface Synchronized
The synchronized annotation determines the synchronization scope of an entity. For
xSocket the synchronized annotation can only be used within a IHandler
class of the stream package.
By default the handler of the stream package is synchronized on the connection level.
That means, for the same connection the handler callback methods will be called in a
serialized manner. Sometime it is desirable that the synchronization should be done
by the handler itself. The synchronization can be deactivated by annotate the handler
as non-synchronized (level OFF). By switching off the synchronization, the correct
order of the call back method calls is not guaranteed. Because the call back method
will be performed within unsynchronized worker threads, race condition could occur.
E.g.
...
import static org.xsocket.Synchronized.Mode.*;
import org.xsocket.Synchronized;
import org.xsocket.stream.BlockingConnection;
@Synchronized(OFF) // deactivate the synchronization by setting scope OFF
class MyHandler implements IDataHandler {
public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException {
...
synchronized (connection) {
ByteBuffer[] data = connection.readByteBufferByDelimiter(DELIMITER);
...
}
...
return true;
}
}
value
public abstract Synchronized.Mode value
- Default:
- org.xsocket.Synchronized.Mode.CONNECTION