More conservative approach for locking of jobs table
This commit is contained in:
parent
0dc14af1aa
commit
5123dad6a8
@ -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<Long, ImportingJob> jobs = new ConcurrentHashMap<Long, ImportingJob>();
|
||||
final static private Map<Long, ImportingJob> jobs = Collections.synchronizedMap(new HashMap<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>();
|
||||
@ -289,7 +289,11 @@ public class ImportingManager {
|
||||
|
||||
static private void cleanUpStaleJobs() {
|
||||
long now = System.currentTimeMillis();
|
||||
for (Long id : jobs.keySet()) {
|
||||
HashSet<Long> keys;
|
||||
synchronized(jobs) {
|
||||
keys = new HashSet<Long>(jobs.keySet());
|
||||
}
|
||||
for (Long id : keys) {
|
||||
ImportingJob job = jobs.get(id);
|
||||
if (job != null && !job.updating && now - job.lastTouched > s_stalePeriod) {
|
||||
job.dispose();
|
||||
|
Loading…
Reference in New Issue
Block a user