forked from lsmyrnaios/UrlsWorker
- Increase the system-reserved memory, in "installAndRun.sh".
- Fix not closing the zip-entry in case of an error.
This commit is contained in:
parent
82d69f3bf5
commit
4fb5becace
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue