Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Bloqueo de Rxjava2Suscribirse vs suscribirse

He leído la explicación sobre blockingSubscribe() y subscribe() pero no puedo escribir ni encontrar un ejemplo para ver la diferencia de estos. Parece que ambos funcionan de la misma manera. ¿Alguien podría proporcionar un ejemplo de estos 2, preferiblemente en Java?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

blockingSubscribe bloquea el hilo actual y procesa los eventos entrantes allí. Puede ver esto ejecutando alguna fuente asíncrona:

 System.out.println("Before blockingSubscribe"); System.out.println("Before Thread: " + Thread.currentThread()); Observable.interval(1, TimeUnit.SECONDS) .take(5) .blockingSubscribe(t -> { System.out.println("Thread: " + Thread.currentThread()); System.out.println("Value: " + t); }); System.out.println("After blockingSubscribe"); System.out.println("After Thread: " + Thread.currentThread());

subscribe no da tal confinamiento y puede ejecutarse en subprocesos arbitrarios:

 System.out.println("Before subscribe"); System.out.println("Before Thread: " + Thread.currentThread()); Observable.timer(1, TimeUnit.SECONDS, Schedulers.io()) .concatWith(Observable.timer(1, TimeUnit.SECONDS, Schedulers.single())) .subscribe(t -> { System.out.println("Thread: " + Thread.currentThread()); System.out.println("Value: " + t); }); System.out.println("After subscribe"); System.out.println("After Thread: " + Thread.currentThread()); // RxJava uses daemon threads, without this, the app would quit immediately Thread.sleep(3000); System.out.println("Done");
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!