-
Aug 19th, 2007, 10:07 AM
#1
ItemProvider not closed when starting tradeJob more than once
I managed to test the tradeJob sample in my own web application, but I run into
following problems:
1. All the *_SEQ tables are not initialized, so I must do it myself. By the way, I am using MySQL.
CREATE TABLE BATCH_STEP_EXECUTION_SEQ (
ID BIGINT
);
CREATE TABLE BATCH_STEP_SEQ (
ID BIGINT
);
CREATE TABLE BATCH_JOB_EXECUTION_SEQ (
ID BIGINT
);
CREATE TABLE BATCH_JOB_SEQ (
ID BIGINT
);
INSERT INTO BATCH_STEP_EXECUTION_SEQ (id) VALUES (1);
INSERT INTO BATCH_STEP_SEQ (id) VALUES (1);
INSERT INTO BATCH_JOB_EXECUTION_SEQ (id) VALUES (1);
INSERT INTO BATCH_JOB_SEQ (id) VALUES (1);
2. I am using an HTTP request to start the configured tradeJob sample. When I start the tradeJob the second time, the "source" reference (fileInputTemplate) in org.springframework.batch.execution.tasklet.suppor t.DefaultFlatFileItemProvider
is at the end of the file, so there is no object returned from method:
public final Object next().
I guess there should be a call of SimpleFlatFileInputSource.close() somewhere.
Is that by design or how can I go around this problem?
<bean id="jobConfiguration" parent="simpleJob">
<property name="name" value="tradeJob" />
<property name="steps">
<list>
<bean id="step1" parent="simpleStep">
<constructor-arg>
<bean class="org.springframework.batch.execution.tasklet .RestartableItemProviderTasklet">
<property name="itemProvider">
<bean
class="org.springframework.batch.execution.tasklet .support.DefaultFlatFileItemProvider">
<property name="source" ref="fileInputTemplate" />
<property name="mapper">
<bean class="org.springframework.batch.sample.mapping.Tr adeFieldSetMapper" />
</property>
<property name="validator" ref="tradeValidator" />
</bean>
</property>
<property name="itemProcessor">
<bean class="org.springframework.batch.sample.module.pro cess.TradeProcessor"
p:writer-ref="tradeDao" />
</property>
</bean>
</constructor-arg>
</bean>
-
Aug 19th, 2007, 01:55 PM
#2
Nice analysis. The SimpleFlatFileInputSource lifecycle needs to be handled by the Spring container, so that its close method is called on container shutdown. One way to do this is to use scope="step". Another is to use a throwaway container just for this job, which is effectively what the samples do out of the box.
P.S. please use [code]...[/code] to show code snippets in the forum - it makes them easier to read.
Last edited by Dave Syer; Aug 19th, 2007 at 01:58 PM.
Reason: added P.S.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules