Merge pull request #852 from Arcadelia/Duplicate-job-id-fix

Import job duplicate id fix
This commit is contained in:
Tom Morris 2014-07-03 10:34:29 -04:00
commit b21cb56149

View File

@ -86,7 +86,10 @@ public class ImportingManager {
static private RefineServlet servlet; static private RefineServlet servlet;
static private File importDir; static private File importDir;
final static private Map<Long, ImportingJob> jobs = Collections.synchronizedMap(new HashMap<Long, ImportingJob>()); final static private Map<Long, ImportingJob> jobs = Collections.synchronizedMap(new HashMap<Long, ImportingJob>());
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" // Mapping from format to label, e.g., "text" to "Text files", "text/xml" to "XML files"
final static public Map<String, Format> formatToRecord = new HashMap<String, Format>(); final static public Map<String, Format> formatToRecord = new HashMap<String, Format>();
@ -187,7 +190,18 @@ public class ImportingManager {
} }
static public ImportingJob createJob() { 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)); File jobDir = new File(getImportDir(), Long.toString(id));
ImportingJob job = new ImportingJob(id, jobDir); ImportingJob job = new ImportingJob(id, jobDir);