Skip to content

Commit

Permalink
Fix memory leak in the completed/failed indexing task. (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiao authored Dec 30, 2020
1 parent 9104bbc commit b9c01f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
3 changes: 0 additions & 3 deletions dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ public void cstore(final Association as, final int pcid, DicomObject rq, PDVInpu
as.abort();

return;
} else {
//DebugManager.getInstance().debug("Client association permited: " + as.getCallingAET() + "!");
System.err.println("Client association permited: " + as.getCallingAET() + "!");
}

final DicomObject rsp = CommandUtils.mkRSP(rq, CommandUtils.SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
*/
package pt.ua.dicoogle.taskManager;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
Expand All @@ -31,6 +26,11 @@
import pt.ua.dicoogle.sdk.datastructs.Report;
import pt.ua.dicoogle.sdk.task.Task;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
* Singleton that contains all running index tasks
*
Expand All @@ -39,7 +39,9 @@
*/
public class RunningIndexTasks {
private static final Logger logger = LoggerFactory.getLogger(RunningIndexTasks.class);

private static int SOFT_MAX_RUNNINGTASKS = Integer.parseInt(System.getProperty("dicoogle.tasks.softRemoveTasks", "50000"));
private static int NUMBER_RUNNINGTASKS_TO_CLEAN = Integer.parseInt(System.getProperty("dicoogle.tasks.numberTaskClean", "2000"));
private static boolean ENABLE_HOOK = Boolean.valueOf(System.getProperty("dicoogle.tasks.removedCompleted", "true"));
public static RunningIndexTasks instance;

private final Map<String, Task<Report>> taskRunningList;
Expand All @@ -52,17 +54,37 @@ public static RunningIndexTasks getInstance() {
}

public RunningIndexTasks() {
taskRunningList = new HashMap<>();
taskRunningList = new LinkedHashMap<>();
}

public void addTask(String taskUid, Task<Report> task) {
taskRunningList.put(taskUid, task);
if (ENABLE_HOOK){
hookRemoveRunningTasks();
}
}

public boolean removeTask(String taskUid) {
return taskRunningList.remove(taskUid) != null;
}


public void hookRemoveRunningTasks(){

if (this.taskRunningList.size()>SOFT_MAX_RUNNINGTASKS){
int removedTasks = 0 ;
Iterator<String> iterator = this.taskRunningList.keySet().iterator();
while(iterator.hasNext()&& removedTasks<NUMBER_RUNNINGTASKS_TO_CLEAN){
String tId = iterator.next();
Task<?> t = this.taskRunningList.get(tId);
if (t.isCancelled() || t.isDone()){
iterator.remove();
removedTasks++;
}
}
}
}

public boolean stopTask(String taskUid) {
Task<Report> task = taskRunningList.get(taskUid);
if (task != null) {
Expand Down

0 comments on commit b9c01f0

Please sign in to comment.