These are chat archives for ReactiveX/RxJava

Jun 2017
David Karnok
Jun 30 2017 08:05
In RxJava, we use a different style of Schedulers. Our schedulers are designed as a pair of Scheduler and Worker. Each Scheduler has a createWorker() method that returns a Worker that is guaranteed to be FIFO for non-timed tasks. observeOn runs on such worker and thus the item event order is preserved (with the option to make sure errors don't cut ahead as well). I.e., Observable.just("Hello", "world").observeOn(Schedulers.computation()).subscribe(System.out::println); will print the two words in order on the same thread. If you are on 1.x then Schedulers.from() is an option for having a single threaded scheduler. in 2.x there is the Schedulers.single(). I have a 3 part series about RxJava's Schedulers.
Joshua Street
Jun 30 2017 19:00
Hey guys, I'm having a problem with using RxJava in my Spring Boot application. The stack trace is:
java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [META-INF/services/javax.xml.bind.JAXBContext]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading( [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.loader.WebappClassLoaderBase.getResource( [tomcat-embed-core-8.5.15.jar:8.5.15]
    at javax.xml.bind.ContextFinder.find( [na:1.8.0_121]
    at javax.xml.bind.JAXBContext.newInstance( [na:1.8.0_121]
    at javax.xml.bind.JAXBContext.newInstance( [na:1.8.0_121]
    at org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter.getJaxbContext( [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter.createMarshaller( [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter.writeToResult( [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.writeInternal( [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.http.converter.AbstractHttpMessageConverter.write( [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest( [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.client.RestTemplate.doExecute( [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.client.RestTemplate.execute( [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.client.RestTemplate.postForObject( [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at [bin/:na]
    at [bin/:na]
    at$1( [bin/:na]
    at io.reactivex.internal.operators.completable.CompletableFromAction.subscribeActual( ~[rxjava-2.1.0.jar:2.1.0]
    at io.reactivex.Completable.subscribe( ~[rxjava-2.1.0.jar:2.1.0]
    at io.reactivex.internal.operators.completable.CompletableSubscribeOn$ ~[rxjava-2.1.0.jar:2.1.0]
    at io.reactivex.Scheduler$ ~[rxjava-2.1.0.jar:2.1.0]
    at ~[rxjava-2.1.0.jar:2.1.0]
    at ~[rxjava-2.1.0.jar:2.1.0]
    at ~[na:1.8.0_121]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201( ~[na:1.8.0_121]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ ~[na:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor.runWorker( ~[na:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor$ ~[na:1.8.0_121]
    at ~[na:1.8.0_121]
i've talked to some folks in the spring boot channel and they state that it could be related to what thread context class loader RxJava uses
it shouldn't be using Tomcat's, and should be using the Application's
does anyone have insight how i can confirm this is the problem and how to fix it?
Joshua Street
Jun 30 2017 19:18
turns out using the IO scheduler had cached stale threads
shutting down and starting the IO scheduler fixes the problem
David Karnok
Jun 30 2017 20:13
For container usages, you have to manually shutdown the schedulers via Schedulers.shutdown() when the container lifecycle ends. It is also recommended you cancel any outstanding flows before that.
Joshua Street
Jun 30 2017 21:24
thanks @akarnokd for the confirmation.
Paul DeMarco
Jun 30 2017 22:27
hi everyone, i have a function that I'd like to return a completable on whether or not it kicked off the longer running observable correctly.
how can I achieve this?
Completable startNofications() {
         .flatMap(foo -> foo.setupNotification())
         .doOnNext( // Setup correctly, return completable to function)
         .subscribe(data -> ...)