Skip to content

Commit

Permalink
Handle two threads asking for a temp folder at the very same time
Browse files Browse the repository at this point in the history
  • Loading branch information
dgageot committed Jul 2, 2015
1 parent a03064e commit a4ef449
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@
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;
Expand Down Expand Up @@ -70,7 +73,7 @@ public TempFolder provide(BootstrapProperties bootstrapProps) {
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) {
Expand Down

0 comments on commit a4ef449

Please sign in to comment.