Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

451
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda