Rxjava: Observable.interval() not work on new thread????

Created on 12 May 2016  路  8Comments  路  Source: ReactiveX/RxJava

Observable.interval(1, TimeUnit.SECONDS,Schedulers.newThread()).subscribe....

# like the one above,nothing happend. But if you change to "Schedulers.immediate",it will print

"0,1,2,3,4,5..." why ??? I test this in a java module with Android Studio.

Question

Most helpful comment

I've tested that this prints 0 to 19 then exits.

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Observable.interval(1, TimeUnit.SECONDS, Schedulers.newThread()).subscribe(System.out::println);

        Thread.sleep(20_000); // if this is missing then the JVM exits immediately and the new thread is stopped.
    }
}

All 8 comments

I've tested that this prints 0 to 19 then exits.

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Observable.interval(1, TimeUnit.SECONDS, Schedulers.newThread()).subscribe(System.out::println);

        Thread.sleep(20_000); // if this is missing then the JVM exits immediately and the new thread is stopped.
    }
}

Can we close this? @abersnaze made correct statement about finishing of the main thread.

Usually, I wait for thanks or some other indicative response, or 30 days.

I wait for thanks

Thanks!

um........

image

Is that the perfect solution? I have occurred this problem in Android development with rxjava 1.3.8. It lost so many events like the screenshot above.

The number of seconds is 07,11,12,13,27,28,32,33. where is 08,09,10,14...etc? Is that a bug? or I am not using it right?

You could simply specify interval(1, 1, TimeUnit.SECONDS, Schedulers.newThread()).
As for the skips, afaik the logging on android sometimes coalesces output if it looks the same. If you print the aLong there, that should get you a monotone sequence of values.

@akarnokd
Thank you. You are right.
The logging on android do coalesces output if it looks the same.
I have tried print the aLong there, it will not missing any events.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

philleonard picture philleonard  路  3Comments

yubaokang picture yubaokang  路  3Comments

nltran picture nltran  路  4Comments

dzharikhin picture dzharikhin  路  4Comments

perlow picture perlow  路  3Comments