Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

450
Vistas
Server Sent Events Close Connection - Spring Boot

i have one question about SSEEmitter in Java Spring Boot. I have following code to etablish connection between client and server in Java Spring Boot. I have set the timeout of the SseEmitter - object to max value of long.

Now following scenary occurrs: I close the tab in the browser and the sseemitter object on the server don't close. So many objects are on the server. This leads to memory issues.

@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;
    }

How can I say the client to close the object? Kind regards

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda