delay and interval operators do not work properly

爷,独闯天下 提交于 2019-12-02 08:33:28

You have to wait in the main method. Put Thread.sleep(10000) at the very end of the main() method so the Observable has chance to run. RxJava threads are daemon threads that stop when the application thread falls out of the main() method.

public static void main(String[] args) {

    Observable.just("Hello World!", "Keep printing values!")
    .zipWith(Observable.interval(0, 5, TimeUnit.SECONDS), (a, b) -> a)
    .subscribe(v -> 
        System.out.println(Thread.currentThread() + ": " + v)
    );

    Thread.sleep(10000);  // <-----------------------------------

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!