X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FProjectInserter.java;h=dd85bf343e88b292b6267f9f35b019e881406dc9;hb=9eafefbca8ddf6c20500a78789a474000cdfe457;hp=1504a9fb7891868d7af617d2e962565ec73fbc45;hpb=f936411037a6ec1afbc5efbb17dc9b0136adda76;p=jSite.git diff --git a/src/main/java/de/todesbaum/jsite/application/ProjectInserter.java b/src/main/java/de/todesbaum/jsite/application/ProjectInserter.java index 1504a9f..dd85bf3 100644 --- a/src/main/java/de/todesbaum/jsite/application/ProjectInserter.java +++ b/src/main/java/de/todesbaum/jsite/application/ProjectInserter.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; @@ -65,7 +66,7 @@ public class ProjectInserter implements FileScannerListener, Runnable { private static final int random = (int) (Math.random() * Integer.MAX_VALUE); /** Counter for FCP connection identifier. */ - private static int counter = 0; + private static final AtomicInteger counter = new AtomicInteger(); private final ProjectInsertListeners projectInsertListeners = new ProjectInsertListeners(); @@ -172,7 +173,7 @@ public class ProjectInserter implements FileScannerListener, Runnable { this.progressListener = progressListener; fileScanner = new FileScanner(project); fileScanner.addFileScannerListener(this); - new Thread(fileScanner).start(); + fileScanner.startInBackground(); } /** @@ -296,7 +297,7 @@ public class ProjectInserter implements FileScannerListener, Runnable { completionLatch.countDown(); } }); - new Thread(fileScanner).start(); + fileScanner.startInBackground(); while (completionLatch.getCount() > 0) { try { completionLatch.await(); @@ -328,7 +329,7 @@ public class ProjectInserter implements FileScannerListener, Runnable { /* create connection to node */ synchronized (lockObject) { - connection = freenetInterface.getConnection("project-insert-" + random + counter++); + connection = freenetInterface.getConnection("project-insert-" + random + counter.getAndIncrement()); } connection.setTempDirectory(tempDirectory); boolean connected = false; @@ -349,7 +350,7 @@ public class ProjectInserter implements FileScannerListener, Runnable { /* collect files */ int edition = project.getEdition(); String dirURI = "USK@" + project.getInsertURI() + "/" + project.getPath() + "/" + edition + "/"; - ClientPutComplexDir putDir = new ClientPutComplexDir("dir-" + counter++, dirURI, tempDirectory); + ClientPutComplexDir putDir = new ClientPutComplexDir("dir-" + counter.getAndIncrement(), dirURI, tempDirectory); if ((project.getIndexFile() != null) && (project.getIndexFile().length() > 0)) { FileOption indexFileOption = project.getFileOption(project.getIndexFile()); Optional changedName = indexFileOption.getChangedName();