diff --git a/installAndRun.sh b/installAndRun.sh index 4d9500c..e7d7cb6 100755 --- a/installAndRun.sh +++ b/installAndRun.sh @@ -65,7 +65,7 @@ if [[ justInstall -eq 0 ]]; then # Update the max-heap-size based on the machine's physical memory. machine_memory_mb=$(grep MemTotal /proc/meminfo | awk '{print $2}' | xargs -I {} echo "scale=4; {}/1024" | bc) # It returns the size in MB. - max_heap_size_mb=$(echo "($machine_memory_mb - 768)/1" | bc) # Leave 768 MB to the system (the "()/1" is used to take the floor value). + max_heap_size_mb=$(echo "($machine_memory_mb - 1024)/1" | bc) # Leave 1024 MB to the system (the "()/1" is used to take the floor value). # Now, we replace the "-Xmx" parameter inside the "./build.gradle" file, with "-Xmx${max_heap_size}m" echo -e "\n\nThe max-heap-size (-Xmx) will be set to: ${max_heap_size_mb}m\n\n" sed -i "s/'-Xmx[0-9]\+[gm]'/'-Xmx${max_heap_size_mb}m'/g" ./build.gradle diff --git a/src/main/java/eu/openaire/urls_worker/util/FilesZipper.java b/src/main/java/eu/openaire/urls_worker/util/FilesZipper.java index 25a113d..aaa9e26 100644 --- a/src/main/java/eu/openaire/urls_worker/util/FilesZipper.java +++ b/src/main/java/eu/openaire/urls_worker/util/FilesZipper.java @@ -43,14 +43,15 @@ public class FilesZipper // This method is "synchronized" to avoid any future problems with shared-buffer, if the requests are asynchronous. private static synchronized boolean zipAFile(String fileName, ZipOutputStream zos, String baseDir) { + boolean shouldCloseEntry = false; // Useful in order to close the entry in case of an exception. String fullFileName = baseDir + fileName; try ( BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fullFileName), BUFFER_SIZE) ) { zos.putNextEntry(new ZipEntry(fileName)); + shouldCloseEntry = true; int count; while ( (count = bis.read(dataBuffer, 0, BUFFER_SIZE)) != -1 ) { zos.write(dataBuffer, 0, count); } - zos.closeEntry(); // close the entry here (not the ZipOutputStream) } catch (FileNotFoundException fnfe) { logger.error("Error zipping file: " + fullFileName, fnfe.getMessage()); return false; @@ -58,6 +59,14 @@ public class FilesZipper if ( ! e.getMessage().contains("duplicate") ) logger.error("Error zipping file: " + fullFileName, e); return false; + } finally { + if ( shouldCloseEntry ) { + try { + zos.closeEntry(); // close the entry here (not the ZipOutputStream) + } catch (IOException e) { + logger.error("", e); + } + } } return true; }