Skip to main content

Observable using interval

Updated 1 min readMarkdown
Part of seriesJava

Interval are timed observables. They tell to perform an event at regular basis. Intervals will help to perform a task regularly.

Below code is a way to create a Timed interval example.

The demo Interval will keep getting invoked at regular interval of a second. We have added a sleep that that we can see the events getting logged.

Since it is observed computation thread so sleep will help us in seeing the logs.

23-01-20 13:17:53 [main] [INFO ] [c.c.l.rxjava.observers.DemoObserver]- onSubscribe
23-01-20 13:17:54 [RxComputationThreadPool-2] [INFO ] [c.c.l.rxjava.observers.DemoObserver]- onNext -> 0
23-01-20 13:17:55 [RxComputationThreadPool-2] [INFO ] [c.c.l.rxjava.observers.DemoObserver]- onNext -> 1
23-01-20 13:17:56 [RxComputationThreadPool-2] [INFO ] [c.c.l.rxjava.observers.DemoObserver]- onNext -> 2

 

69 views

About the author

  • DigitalYogi builds interactive System Design (HLD), Low-Level Design (LLD), Visual DSA & Spring AI playbooks for working Java backend engineers. Workbench: kb.digitalyogi.tech · Free 12-sheet templates: learn.digitalyogi.tech/system

No comments yet. Be the first to comment.

More from this blog