Skip to content

Commit

Permalink
stup
Browse files Browse the repository at this point in the history
  • Loading branch information
smashyalts committed Mar 1, 2024
1 parent 9a4995c commit 5373516
Showing 1 changed file with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.*;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

Expand All @@ -19,6 +20,11 @@ public static void main(String args) throws IOException {

zipOut.close();
fos.close();

pool.shutdown(); // Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted
pool.awaitQuiescence(60, TimeUnit.SECONDS); // Wait for all tasks to complete for up to 60 seconds

// Suggest to the JVM that it's a good time to run the Garbage Collector
System.gc();
}

Expand All @@ -42,11 +48,13 @@ protected void compute() {
if (!fileName.endsWith("/")) {
fileName += "/";
}
try {
zipOut.putNextEntry(new ZipEntry(fileName));
zipOut.closeEntry();
} catch (IOException e) {
e.printStackTrace();
synchronized (zipOut) {
try {
zipOut.putNextEntry(new ZipEntry(fileName));
zipOut.closeEntry();
} catch (IOException e) {
e.printStackTrace();
}
}

File[] children = fileToZip.listFiles();
Expand All @@ -55,16 +63,18 @@ protected void compute() {
action.fork(); // Start the action asynchronously
}
} else {
try (FileInputStream fis = new FileInputStream(fileToZip)) {
ZipEntry zipEntry = new ZipEntry(fileName);
zipOut.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
synchronized (zipOut) {
try (FileInputStream fis = new FileInputStream(fileToZip)) {
ZipEntry zipEntry = new ZipEntry(fileName);
zipOut.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Expand Down

0 comments on commit 5373516

Please sign in to comment.