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

230
Visualizações
is there a way to read a InputStream asynchronously with Reactor or transform to bytes?

I'm trying to upload a file to S3, but JVM says that i have a thread-blocking method calls in code fragments where threads should not be blocked when calling file.readAllBytes(), so is there a way to is there a way to make the method asynchronous with Flux or Mono? or any other way to solve that problem?

private Mono<Boolean> uploadFile(InputStream file, String bucket, String name) {
        try {
            return uploadAdapter.uploadObject(bucket,name,file.readAllBytes());
        } catch (IOException e) {
            return Mono.just(false);
        }
    }
@Override
    public Mono<Boolean> uploadObject(String bucketName, String objectKey, byte[] fileContent) {
        return Mono.fromFuture(
                        s3AsyncClient.putObject(configurePutObject(bucketName, objectKey),
                                AsyncRequestBody.fromBytes(fileContent)))
                .map(response -> response.sdkHttpResponse().isSuccessful());
    }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Since InputStream is a synchronous API, you have 2 choices, and that's true about any other synchronous API:

  1. To switch to another API. No kidding, this may be a good and possible solution for many problems. The reactive concepts and asynchronous in general are very common and for most of the needs, there is an alternative async library that will do the same thing. In your case, you can use java.nio2, or functions from the Reactor-Netty library, which has great solutions for this use case.
  2. Use another scheduler. Project reactor suggests that all of your asynchronous calls will operate on one non-blocking scheduler, and for synchronous calls, use another (blocking) thread-per-request scheduler. There are two schedulers like this that you can use: single() and boundedElastic(). The difference is that boundedElastic() limits the number of threads that you can open, so you will end up using your threads as blocking queues, which is safer than single().
over 4 years ago · Santiago Trujillo Relatório
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