Skip to content

Instantly share code, notes, and snippets.

@hkurokawa
Last active July 14, 2016 10:34
Show Gist options
  • Save hkurokawa/9889877e7ab6111ec0874fa2863e29fa to your computer and use it in GitHub Desktop.
Save hkurokawa/9889877e7ab6111ec0874fa2863e29fa to your computer and use it in GitHub Desktop.
A sample code to reproduce an issue that the unsubscription thread is sometimes different from the subscription thread.
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.schedulers.Schedulers;
public class UsingResourceSample {
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < 10; i++) {
Observable.using(() -> {
System.out.println("Getting @" + Thread.currentThread());
return null;
}, Observable::just, (aVoid) -> System.out.println("Closing @" + Thread.currentThread()))
.subscribeOn(Schedulers.io())
.subscribe()
.unsubscribe();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment