diff options
author | David Gageot <david@gageot.net> | 2015-07-02 19:28:43 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2015-07-02 19:30:06 +0200 |
commit | a4ef4494e4697e6772b0e7acc411da8a3b42c359 (patch) | |
tree | 971b598ea8c577a9f416df1fe44ea5d8867f8db7 | |
parent | a03064e95f49b09e576432dc3547c50e7429eac6 (diff) | |
download | sonarqube-a4ef4494e4697e6772b0e7acc411da8a3b42c359.tar.gz sonarqube-a4ef4494e4697e6772b0e7acc411da8a3b42c359.zip |
Handle two threads asking for a temp folder at the very same time
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java index 9b4d199df83..487296f1ba9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java @@ -36,10 +36,13 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; public class TempFolderProvider extends LifecycleProviderAdapter { private static final Logger LOG = Loggers.get(TempFolderProvider.class); private static final long CLEAN_MAX_AGE = TimeUnit.DAYS.toMillis(21); + private static final AtomicLong nextId = new AtomicLong(); + static final String TMP_NAME_PREFIX = ".sonartmp_"; private System2 system; @@ -70,7 +73,7 @@ public class TempFolderProvider extends LifecycleProviderAdapter { LOG.error(String.format("failed to clean global working directory: %s", workingPath), e); } - Path tempDir = workingPath.resolve(TMP_NAME_PREFIX + System.currentTimeMillis()); + Path tempDir = workingPath.resolve(TMP_NAME_PREFIX + System.currentTimeMillis() + nextId.incrementAndGet()); try { Files.createDirectories(tempDir); } catch (IOException e) { |