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

190
Views
Servidor Enviado Eventos Cerrar Conexión - Spring Boot

Tengo una pregunta sobre SSEEmitter en Java Spring Boot. Tengo el siguiente código para establecer la conexión entre el cliente y el servidor en Java Spring Boot. Establecí el tiempo de espera del objeto SseEmitter en el valor máximo de long.

Ahora ocurre lo siguiente: cierro la pestaña en el navegador y el objeto sseemitter en el servidor no se cierra. Hay tantos objetos en el servidor. Esto conduce a problemas de memoria.

 @RequestMapping(value = "/subscribe", consumes = MediaType.ALL_VALUE) public SseEmitter subscribe() { System.out.println("SUBSCRIBE CALLED!"); System.out.println(emitters.size()); SseEmitter x = new SseEmitter(Long.MAX_VALUE); try { x.send(SseEmitter.event().name("INIT")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } x.onCompletion(()->{ System.out.println("ON COMPLETION CALLED!"); emitters.remove(x); }); x.onTimeout(()->{ System.out.println("ON TIMEOUT CALLED!"); emitters.remove(x); }); emitters.add(x); return x; }

¿Cómo puedo decirle al cliente que cierre el objeto? Saludos cordiales

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Supongo que está utilizando "emisores" para enviar futuras actualizaciones. Intente completar el emisor y eliminarlo de "emimtter" en el bloque catch (IOException) donde envía la actualización del emisor:

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!