Package rx.subjects

Class SerializedSubject<T,R>

java.lang.Object
rx.Observable<R>
rx.subjects.Subject<T,R>
rx.subjects.SerializedSubject<T,R>
Type Parameters:
T - the input value type
R - the output value type
All Implemented Interfaces:
Observer<T>

public class SerializedSubject<T,R> extends Subject<T,R>
Wraps a Subject so that it is safe to call its various on methods from different threads.

When you use an ordinary Subject as a Subscriber, you must take care not to call its Observer.onNext(T) method (or its other on methods) from multiple threads, as this could lead to non-serialized calls, which violates the Observable contract and creates an ambiguity in the resulting Subject.

To protect a Subject from this danger, you can convert it into a SerializedSubject with code like the following:


 mySafeSubject = new SerializedSubject( myUnsafeSubject );