0

I am using RxJava for a server microservice project, where using Jetty as HTTP Servlet server.

I am handling requests either from client or main server with Observable for different flows. When a request hitting the api below, I will return a Response after Observable finishes the job.

@GET
@Path("{uuid}")
@Produces(MediaType.APPLICATION_JSON)
public Response doThingsForClient(@PathParam("uuid") String uuid) {
   Worker worker = new Worker(uuid);
   worker.run();
   return Response.ok("Awesome").build();
}

class Worker {
   String uuid = null;
   public Worker(String uuid) {
      this.uuid = uuid;
   }

   public void run() {
      Observable.concat(Observable1,Observable2,Observable3);
   }
}

I am wondering if I need to dispose these Observables or Flowables. According to this: Does RxJava2 auto dispose observable when they call completed or error? and the RxJava3 sourcecode, i don't think Flowable at least is disposed automatically?

If I need to manually dispose the resources, Is it better to create a CompositeDisposable, then add disposable to the CompositeDisposable at each Observer(Observable1...Observable3)'s onSubscribe() being called, call compositeDisposable.dispose() after the concat finishes.

Should I also monitor the Jetty AbstractLifeCycle to dispose these Observables(It sounds similar as Android)? I am not sure how other people are using RxJava at the server side, open to any suggestions to these questions and general Rx approach at server projects.

Thanks!

  • It's tough to tell from the question since we don't see what the observers are doing. Generally speaking, I don't believe you have to dispose manually if the observables are completing. – TrogDor Apr 24 '20 at 20:47
  • yeah, onComplete should dispose the resources. – Daayoung Code May 07 '20 at 18:46

0 Answers0