Switch to ConcurrentHashMap for jobs table to allow multiple accessors

This commit is contained in:
Tom Morris 2013-07-25 15:36:54 -04:00
parent 0ff2d7ed9f
commit dc206e1889

View File

@ -44,6 +44,7 @@ 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;
@ -82,7 +83,7 @@ public class ImportingManager {
static private RefineServlet servlet;
static private File importDir;
final static private Map<Long, ImportingJob> jobs = new HashMap<Long, ImportingJob>();
final static private Map<Long, ImportingJob> jobs = new ConcurrentHashMap<Long, ImportingJob>();
// 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>();
@ -288,12 +289,11 @@ public class ImportingManager {
static private void cleanUpStaleJobs() {
long now = System.currentTimeMillis();
for (Long id : new HashSet<Long>(jobs.keySet())) {
for (Long id : jobs.keySet()) {
ImportingJob job = jobs.get(id);
if (job != null && !job.updating && now - job.lastTouched > s_stalePeriod) {
job.dispose();
jobs.remove(id);
logger.info("Disposed " + id);
}
}