首页 文章

Spring Batch Item Writer运行infinte times并且无法结束编写器进程

提问于
浏览
-1

问题是:在读者类中,我从数据库和编写器类中读取数据只是打印列表,但它运行了很多次 . 它无法完成这个过程 . 我附上了阅读器处理器编写器和xml类 . 任何人都建议我提供 Spring 季批量建议,我无法理解读者和作者的概念 .

我在这里错过了什么,任何人都可以建议我这份工作

这是我的xml文件:

<beans xmlns = "http://www.springframework.org/schema/beans" 
   xmlns:batch = "http://www.springframework.org/schema/batch" 
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation = "http://www.springframework.org/schema/batch 
      http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> 

    <import resource="context-model.xml"/> 
    <!-- JobRepository and JobLauncher are configuration/setup classes -->
    <bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean" />

    <bean id="jobLauncher"   class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository" />
    </bean>

 <!--THis is my reader writer and processor xml  -->
    <bean id="Reader" class="com.ibm.dao.Reader"/>
     <bean id="Processor" class="com.ibm.dao.Processor" />
    <!-- com.ibm.dao.Writer -->
     <bean id="Writer_pro" class=" com.ibm.dao.Writer">
     <!--   <property name="sessionFactory" ref="sessionFactory" /> -->  
          </bean>

    <!-- Defining a job--> 
   <batch:job id = "CancellationLetterJob">  
      <!-- Defining a Step --> 
      <batch:step id = "step1"> 
<batch:tasklet> 
                <batch:chunk  reader="Reader" processor="Processor"  writer="Writer_pro" commit-interval='0' /> 
</batch:tasklet> 

      </batch:step>    
   </batch:job>  

</beans> 


****************and this is my writer class code********************:

public class Writer实现ItemWriter {

@Override
    public void write(List<? extends TPOL> pol) throws Exception {

    System.out.println( pol.get(0).getId());

        for(TPOL list :pol )
        {
        System.out.println("list");

        }

        return;

    }

*******我的读者课程

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.batch.api.chunk.ItemProcessor;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.itextpdf.text.log.SysoCounter;
import com.javatpoint.mypackage.TPOL;
import com.javatpoint.mypackage.test;
import com.javatpoint.mypackage.writer;
import com.ibm.dao.*;


public class Reader implements ItemReader<TPOL> {
    public static Logger logger = Logger.getLogger(test.class);
    /*public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws Exception {  


    }
    */
    @Override
    public TPOL read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
        TPOL pol= new TPOL();
        //pol.setId(102);
        logger.info("TPOL data fetched");
        pol.setSystemid(1001);
        logger.info(pol);
        System.out.println("data updated in DB");
        return pol;
    }

***********我的处理器类

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemWriter;

import com.javatpoint.mypackage.TPOL;
import com.javatpoint.mypackage.test;
import com.javatpoint.mypackage.writer;

public class Processor implements ItemProcessor<TPOL, TPOL>
{
    public static Logger logger = Logger.getLogger(test.class);

    @Override
    public TPOL process(TPOL pol) throws Exception {


        Configuration  config= new AnnotationConfiguration().addAnnotatedClass(TPOL.class).configure();
        SessionFactory factory = config.buildSessionFactory();
        Session sf=factory.openSession();   
        Transaction tr=sf.beginTransaction();

        logger.info(tr);

        sf.save(pol);
        logger.info("save"+sf.save(pol));

        Criteria cr = sf.createCriteria(TPOL.class);
        //cr.add(Restrictions.eq("systemid", 1000));
        ArrayList<TPOL> list = (ArrayList<TPOL>) cr.list();

        for(TPOL pol1: list)
        {
            //System.out.println("OUTPUT VALUE::"+pol1.getId()+" "+pol1.getSystemid());
            System.out.println(pol1.getSystemid());

    }
        //System.out.println("size"+list.size());
        //System.out.println("successfully saved "); 
        tr.commit();
        sf.close();
        return pol;
    }

}



MY output is :

log4j:WARN No such property [maxBackupIndex] in org.apache.log4j.FileAppender.
log4j:WARN No such property [datePattern] in org.apache.log4j.FileAppender.
log4j:WARN No such property [maxFileSize] in org.apache.log4j.FileAppender.
data updated in DB
Hibernate: insert into T_S2M_MAPPING (SYS_ID) values (?)
Hibernate: select this_.ID as ID0_0_, this_.SYS_ID as SYS2_0_0_ from T_S2M_MAPPING this_
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
765
list
data updated in DB
Hibernate: insert into T_S2M_MAPPING (SYS_ID) values (?)
Hibernate: select this_.ID as ID2_0_, this_.SYS_ID as SYS2_2_0_ from T_S2M_MAPPING this_
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
766
list
data updated in DB
Hibernate: insert into T_S2M_MAPPING (SYS_ID) values (?)
Hibernate: select this_.ID as ID4_0_, this_.SYS_ID as SYS2_4_0_ from T_S2M_MAPPING this_
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
767
list
data updated

它不能结束这个过程 . 任何人都可以建议我这份工作

1 回答

相关问题