Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!