From a0d4eb0058e8c3929d4224e848dd4b2f0db9e8d5 Mon Sep 17 00:00:00 2001 From: Frank Wennerdahl Date: Wed, 5 Feb 2014 12:21:02 +0100 Subject: [PATCH] Job id duplicate fix Changed how job id's are created to avoid the same id to be assigned to two concurrent jobs. --- .../refine/importing/ImportingManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main/src/com/google/refine/importing/ImportingManager.java b/main/src/com/google/refine/importing/ImportingManager.java index 2111a1af6..a14018ae8 100644 --- a/main/src/com/google/refine/importing/ImportingManager.java +++ b/main/src/com/google/refine/importing/ImportingManager.java @@ -86,7 +86,10 @@ public class ImportingManager { static private RefineServlet servlet; static private File importDir; + final static private Map jobs = Collections.synchronizedMap(new HashMap()); + static private long jobIdCounter = 0; + final static private Object jobIdLock = new Object(); // Mapping from format to label, e.g., "text" to "Text files", "text/xml" to "XML files" final static public Map formatToRecord = new HashMap(); @@ -187,7 +190,18 @@ public class ImportingManager { } static public ImportingJob createJob() { - long id = System.currentTimeMillis() + (long) (Math.random() * 1000000); + long id; + + synchronized(jobIdLock) { + ++jobIdCounter; + + // Avoid negative job id's when the counter wraps around. + if (jobIdCounter < 0) + jobIdCounter = 1; + + id = jobIdCounter; + } + File jobDir = new File(getImportDir(), Long.toString(id)); ImportingJob job = new ImportingJob(id, jobDir);