Found what is causing the out-of-memory issue, the below code in the ThreadUtils.java class creates a new thread for each dataset, ensuring tasks for the same object are executed one after another but possibly using more resources. As it's not reusing the threads it isn't possible to create a new thread if there are a lot of datasets.
public void execute(Object obj, CThreadWorker<?, ?> worker) {
if (obj == null || worker == null) {
throw new IllegalArgumentException("None of parameters can be null");
}
ThreadUtils.getPrimaryExecutor(obj).execute(worker);
}
public synchronized static Executor getPrimaryExecutor(Object key) {
Executor exec = obj2exec.get(key);
if (exec == null) {
exec = Executors.newSingleThreadExecutor();
obj2exec.put(key, exec);
}
return exec;
}
Changed this code to the below code which uses ExecutorService to manage the threads and their lifecycle, this doesn't give any error but the time taken to remove all the UCSC datasets (around 9,500) is around 4 minutes 30 seconds. That is because a few parts of code require sequential execution, if we want to optimize it, it might take a lot of effort, investigation, and a lot of code change.
public class ExecutorServiceManager {
private static final int THREAD_POOL_SIZE = Runtime.getRuntime().availableProcessors();
private static final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
public static ExecutorService getExecutorService() {
return executorService;
}
}
public void executeForRemoveDatasets(Object obj, CThreadWorker<?, ?> worker) {
if (obj == null || worker == null) {
throw new IllegalArgumentException("None of parameters can be null");
}
ExecutorServiceManager.getExecutorService().execute(worker);
}
As discussed with Nowlan Freese, the best option to resolve the issue at this point is to remove narrowPeak and bigWig file types, as they have a lot of datasets, and this will result in removing the datasets faster without any issues and takes far less time. Here is the updated branch: https://bitbucket.org/jaya-sravani/integrated-genome-browser/branch/IGBF-3853. Added it as a separate commit to make it more understandable.
Investigated the issue, it is happening because of the changes included in this commit: https://bitbucket.org/lorainelab/integrated-genome-browser/commits/a2c9ebd52cb1ccd4105d056b14ce86d89fe40114 when this commit is reverted, it is working properly, working on finding the exact issue and fixing it.