From 5123dad6a8988b16402b8374e4468a0bedda4e1e Mon Sep 17 00:00:00 2001 From: Tom Morris Date: Fri, 26 Jul 2013 18:51:08 -0400 Subject: [PATCH] More conservative approach for locking of jobs table --- .../com/google/refine/importing/ImportingManager.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main/src/com/google/refine/importing/ImportingManager.java b/main/src/com/google/refine/importing/ImportingManager.java index 9cbd2fc6d..3752c7b9f 100644 --- a/main/src/com/google/refine/importing/ImportingManager.java +++ b/main/src/com/google/refine/importing/ImportingManager.java @@ -35,6 +35,7 @@ package com.google.refine.importing; import java.io.File; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -44,7 +45,6 @@ import java.util.Properties; import java.util.Set; import java.util.Timer; import java.util.TimerTask; -import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.io.FileUtils; import org.json.JSONException; @@ -83,7 +83,7 @@ public class ImportingManager { static private RefineServlet servlet; static private File importDir; - final static private Map jobs = new ConcurrentHashMap(); + final static private Map jobs = Collections.synchronizedMap(new HashMap()); // Mapping from format to label, e.g., "text" to "Text files", "text/xml" to "XML files" final static public Map formatToRecord = new HashMap(); @@ -289,7 +289,11 @@ public class ImportingManager { static private void cleanUpStaleJobs() { long now = System.currentTimeMillis(); - for (Long id : jobs.keySet()) { + HashSet keys; + synchronized(jobs) { + keys = new HashSet(jobs.keySet()); + } + for (Long id : keys) { ImportingJob job = jobs.get(id); if (job != null && !job.updating && now - job.lastTouched > s_stalePeriod) { job.dispose();