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

105
Visualizações
Java URL Connection times out on subsequent call

I am invoking java classes on a Javascript engine, so I am limited on what I can do.

The code works fine, but when I invoke the Javascript on a loop, it times out after the first invocation.

The code just downloads a ZIP from a url, and stores it to a path. Here is the full code:

var result = (function() {
    var URL = Packages.java.net.URL;
    var Files = Packages.java.nio.file.Files;
    var Paths = Packages.java.nio.file.Paths;
    var StandardCopyOption = Packages.java.nio.file.StandardCopyOption;

    var urlAddr = new URL(
            target_url
        );
    
     
    var connection = urlAddr.openConnection();
 
    connection.setRequestMethod("GET");
    connection.setRequestProperty("Authorization", bearer);
    
    connection.setReadTimeout(20*1000);
    
    connection.connect();

    Files.copy(connection.getInputStream(), Paths.get(file_path+new_filename+".zip"), StandardCopyOption.REPLACE_EXISTING);
 

    return "";
}());

The error I am getting from the server:

Java Exception: java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out: during call of javax.script.ScriptEngine.eval.

Before someone suggests, I cant get away from the java being called inside the javascript.

I thought it could be a connection being kept open.

UPDATE: this javascript for some reason is always taking 5 minutes to run....

UPDATE2: Files.copy seems to be the issue, since its the one taking the 5 minutes from the code.... the file is very small, and 5 min wouldnt justify

about 4 years ago · Juan Pablo Isaza
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