Announcement Announcement Module
Collapse
No announcement yet.
issue whith removeInactiveExecutions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • issue whith removeInactiveExecutions

    Hi,
    I found this issue in my spring Batch project.
    This project is a little more that the standard Batch-admin web project.

    Once a job of mine is terminated, it leads removeInactiveExecutions to raise the following exception:

    ERROR support.TaskUtils$LoggingErrorHandler (TaskUtils.java:95) - Unexpected error occurred in scheduled task.
    java.util.ConcurrentModificationException
    at java.util.AbstractList$Itr.checkForComodification( Unknown Source)
    at java.util.AbstractList$Itr.next(Unknown Source)
    at org.springframework.batch.admin.service.SimpleJobS ervice.removeInactiveExecutions(SimpleJobService.j ava:466)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.scheduling.support.ScheduledMe thodRunnable.run(ScheduledMethodRunnable.java:64)
    at org.springframework.scheduling.support.DelegatingE rrorHandlingRunnable.run(DelegatingErrorHandlingRu nnable.java:53)
    at java.util.concurrent.Executors$RunnableAdapter.cal l(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRunAndRe set(Unknown Source)
    at java.util.concurrent.FutureTask.runAndReset(Unknow n Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$S cheduledFutureTask.access$101(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$S cheduledFutureTask.runPeriodic(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$S cheduledFutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
    at java.lang.Thread.run(Unknown Source)

    I see the problem happend in this fragment of code:
    Code:
    	
    package org.springframework.batch.admin.service;
    (...)
    public class SimpleJobService implements JobService, DisposableBean {
    (...)
    
    /**
    	 * Check all the active executions and see if they are still actually
    	 * running. Remove the ones that have completed.
    	 */
    	@Scheduled(fixedDelay = 60000)
    	public void removeInactiveExecutions() {
    
    		for (Iterator<JobExecution> iterator = activeExecutions.iterator(); iterator.hasNext();) {
    			JobExecution jobExecution = iterator.next();
    			try {
    				jobExecution = getJobExecution(jobExecution.getId());
    			}
    			catch (NoSuchJobExecutionException e) {
    				logger.error("Unexpected exception loading JobExecution", e);
    			}
    			if (!jobExecution.isRunning()) {
    				iterator.remove();
    			}
    		}
    
    	}
    I see this happed because there are two Thread ( Thread[pool-1-thread-1] and Thread[pool-2-thread-1])
    that call the SimpleJobService removeInactiveExecutions()
    when the first of the two threads removes the job, comes the second that try to iterate the list and it raise the above mentioned ConcurrentModificationException.


    Is this a bug or is due to my wrong confuration?
    is it normal to have two thread that concurrently performs a check for terminated jobs?

    Many thanks

    Franco

    p.s.
    this is the job configuration:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:batch="http://www.springframework.org/schema/batch"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    						http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    						http://www.springframework.org/schema/context 
    						http://www.springframework.org/schema/context/spring-context-3.1.xsd
          					http://www.springframework.org/schema/batch
          					http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
    <import resource="classpath*:/META-INF/spring/batch/override/env-context.xml" /> 
    
    
    	<job id="sendEmailJob" xmlns="http://www.springframework.org/schema/batch" restartable="false" >
        	<step id="sendEMailStep">
            	<tasklet ref="sendMailManager" />
         	</step>
     	</job>
     	
     	<bean id="sendMailManager" class ="com.customerx.tasklets.SendMailTasklet" scope="step">
     		<property name="passwordContainer" ref="passwordContainer"/>	
     		<property name="parameterencoder" ref="encoderHEX" ></property>
        		<property name="mailSender" ref="mailSender"/>
         		<property name="sendMailService" ref="sendMailService"/>
     	</bean>
     	
    	<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
         		<property name="javaMailProperties">
            		<props>
                			<prop key="mail.smtp.auth">True</prop> 
             		</props>
         		</property>
     	</bean>
     	
     	<bean id="sendMailService" class="com.customerx.batch.SendMailService" />
    
     	<bean class="org.springframework.batch.core.scope.StepScope" />
    
    </beans>
Working...
X