WASdev / standards.jsr352.jbatch

Home of 'jbatch', a compatible implementation of the Jakarta Batch specification (and the former Reference Implementation for the JSR 352, Batch Applications for the Java Platform specification).
Other
21 stars 18 forks source link

JobEndCallbackManagerImpl consumes heap in the long run #51

Open k2sd opened 7 years ago

k2sd commented 7 years ago

I'm afraid the completedExecutions field in the JobEndCallbackManagerImpl consumes heap if a lot of job executions get done without restarting the 'job end callback service.'

An execution is finished, the execution id is added to the map as follows:

@Override
    public synchronized void done(long jobExecutionId) {
        if (logger.isLoggable(Level.FINER)) {            
            logger.finer("Firing callbacks for job execution id: " + jobExecutionId);
        }
        completedExecutions.add(jobExecutionId);
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

There seems no method that reduces the size of the map, so I think it will eventually exhaust heap (Of course it depends on how many executions are done while the service is alive).

Is it necessary to check completed execution ids when calling the job-end-callbacks?

k2sd commented 7 years ago

I'm not quite so sure but we might want to prevent completedExecutions from being added if there is no callbacks.

diff --git a/com.ibm.jbatch.container/src/main/java/com/ibm/jbatch/container/callback/JobEndCallbackManagerImpl.java b/com.ibm.jbatch.container/src/main/java/com/ibm/jbatch/container/callback/JobEndCallbackManagerImpl.java
old mode 100755
new mode 100644
index da64700..3fd33d3
--- a/com.ibm.jbatch.container/src/main/java/com/ibm/jbatch/container/callback/JobEndCallbackManagerImpl.java
+++ b/com.ibm.jbatch.container/src/main/java/com/ibm/jbatch/container/callback/JobEndCallbackManagerImpl.java
@@ -59,6 +59,9 @@

    @Override
    public synchronized void done(long jobExecutionId) {
+       if (callbacks.isEmpty()) {
+           return;
+       }
        if (logger.isLoggable(Level.FINER)) {            
            logger.finer("Firing callbacks for job execution id: " + jobExecutionId);
        }