RESOLVED - issue BATCH-603: JobExecution fields could be modified in another Thread and are not volatile

Added final and volatile as appropriate in domain entities.
This commit is contained in:
dsyer
2008-05-09 21:25:22 +00:00
parent a0b7049867
commit 476b24da4d
7 changed files with 33 additions and 65 deletions

View File

@@ -31,21 +31,17 @@ import org.springframework.batch.repeat.ExitStatus;
*/
public class JobExecution extends Entity {
private JobInstance jobInstance;
private final JobInstance jobInstance;
private transient Collection stepExecutions = new HashSet();
private BatchStatus status = BatchStatus.STARTING;
private volatile BatchStatus status = BatchStatus.STARTING;
private Date startTime = null;
private volatile Date startTime = null;
private Date endTime = null;
private volatile Date endTime = null;
private ExitStatus exitStatus = ExitStatus.UNKNOWN;
// Package private constructor for testing
JobExecution() {
}
private volatile ExitStatus exitStatus = ExitStatus.UNKNOWN;
/**
* Because a JobExecution isn't valid unless the job is set, this
@@ -125,10 +121,6 @@ public class JobExecution extends Entity {
return jobInstance;
}
public void setJobInstance(JobInstance jobInstance) {
this.jobInstance = jobInstance;
}
/**
* Accessor for the step executions.
*

View File

@@ -39,9 +39,9 @@ import org.springframework.util.Assert;
*/
public class JobInstance extends Entity {
private JobParameters jobParameters;
private final JobParameters jobParameters;
private String jobName;
private final String jobName;
public JobInstance(Long id, JobParameters jobParameters, String jobName) {
super(id);

View File

@@ -24,17 +24,17 @@ package org.springframework.batch.core;
*/
public class StepContribution {
private int itemCount = 0;
private volatile int itemCount = 0;
private int parentSkipCount;
private final int parentSkipCount;
private int commitCount;
private volatile int commitCount;
private int readSkipCount;
private volatile int readSkipCount;
private int writeSkipCount;
private volatile int writeSkipCount;
private int uncommitedReadSkipCount;
private volatile int uncommitedReadSkipCount;
/**
* @param execution

View File

@@ -35,38 +35,31 @@ import org.springframework.util.Assert;
*/
public class StepExecution extends Entity {
private JobExecution jobExecution;
private final JobExecution jobExecution;
private String stepName;
private final String stepName;
private BatchStatus status = BatchStatus.STARTING;
private volatile BatchStatus status = BatchStatus.STARTING;
private int itemCount = 0;
private volatile int itemCount = 0;
private int commitCount = 0;
private volatile int commitCount = 0;
private int rollbackCount = 0;
private volatile int rollbackCount = 0;
private int readSkipCount = 0;
private volatile int readSkipCount = 0;
private int writeSkipCount = 0;
private volatile int writeSkipCount = 0;
private Date startTime = new Date(System.currentTimeMillis());
private volatile Date startTime = new Date(System.currentTimeMillis());
private Date endTime = null;
private volatile Date endTime = null;
private ExecutionContext executionContext = new ExecutionContext();
private volatile ExecutionContext executionContext = new ExecutionContext();
private ExitStatus exitStatus = ExitStatus.UNKNOWN;
private volatile ExitStatus exitStatus = ExitStatus.UNKNOWN;
private boolean terminateOnly;
/**
* Package private constructor for Hibernate
*/
StepExecution() {
super();
}
private volatile boolean terminateOnly;
/**
* Constructor with mandatory properties.

View File

@@ -31,12 +31,8 @@ public class JobExecutionTests extends TestCase {
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "foo"), new Long(12));
/**
* Test method for
* {@link org.springframework.batch.core.JobExecution#JobExecution()}.
*/
public void testJobExecution() {
assertNull(new JobExecution().getId());
assertNull(new JobExecution(new JobInstance(null,null,"foo")).getId());
}
/**
@@ -150,7 +146,7 @@ public class JobExecutionTests extends TestCase {
}
public void testToStringWithNullJob() throws Exception {
execution = new JobExecution();
execution = new JobExecution(new JobInstance(null,null,"foo"));
assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
assertTrue("JobExecution string does not contain job: " + execution, execution.toString().indexOf("job=") >= 0);
}

View File

@@ -23,7 +23,7 @@ import junit.framework.TestCase;
*/
public class StepContributionTests extends TestCase {
private StepExecution execution = new StepExecution();
private StepExecution execution = new StepExecution("step", null);
private StepContribution contribution = new StepContribution(execution);

View File

@@ -35,22 +35,14 @@ public class StepExecutionTests extends TestCase {
private StepExecution execution = newStepExecution(new StepSupport("stepName"), new Long(23));
private StepExecution blankExecution = new StepExecution("blank", new JobExecution());
private StepExecution blankExecution = newStepExecution(new StepSupport("blank"), null);
/**
* Test method for
* {@link org.springframework.batch.core.JobExecution#JobExecution()}.
*/
public void testStepExecution() {
assertNull(new StepExecution().getId());
assertNull(new StepExecution("step", null).getId());
}
/**
* Test method for
* {@link org.springframework.batch.core.JobExecution#JobExecution()}.
*/
public void testStepExecutionWithNullId() {
assertNull(new StepExecution("stepName", new JobExecution()).getId());
assertNull(new StepExecution("stepName", new JobExecution(new JobInstance(null,null,"foo"))).getId());
}
/**
@@ -138,7 +130,7 @@ public class StepExecutionTests extends TestCase {
public void testNullNameIsIllegal() throws Exception {
try {
new StepExecution(null, new JobExecution());
new StepExecution(null, new JobExecution(new JobInstance(null, null, "job")));
fail();
}
catch (IllegalArgumentException e) {
@@ -183,11 +175,6 @@ public class StepExecutionTests extends TestCase {
assertFalse(stepExecution.equals(blankExecution));
}
public void testEqualsWithNullStep() throws Exception {
Entity stepExecution = newStepExecution(new StepSupport("stepName"), null);
assertFalse(stepExecution.equals(blankExecution));
}
public void testEqualsWithSelf() throws Exception {
assertTrue(execution.equals(execution));
}