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

106
Vistas
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 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