Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Error while closing item reader

  1. #1

    Default Error while closing item reader

    Hi All,

    I have an batch processing that registers the job and start the registered job in different threads(Each job with different parameters).
    All the threads processing successfully, jobs are completed but i am getting following exception in the logs.

    Why this error occurs?
    How come jobs are completed successfully?

    Please find the Already closed text file contain error logs

    I am using Spring batch 2.1
    Hibernate3
    sql server 2005.

    Thanks for your reply in advance.
    Attached Files Attached Files
    Thanks & Regards,
    Arun Duraisamy

  2. #2

    Default

    You are running into synchronization issues. Use the JdbbcCursorReader as a delegate to a synchronized read in your Reader with saveState =false .
    May be the jobs are completing but I am sure your will not see all the rows...did you verify that ?
    By default mostly the reads are not thread safe.

  3. #3

    Default

    Thanks for your reply Sambaran.
    We are using default HibernateCursorItemReader. I have verified the data. There is to scenario's
    1. Some time Job is completed successfully and data also proper but exception we are getting in logs.
    2. Some time job is failed and data is improper.

    According your suggestion I will add the delegate and synchronized the read.

    One more doubts.
    We are getting Connection Already close and Connection Reset exception. What this exception occurs.

    We are getting this issues while running our batch in Production environment(AIX). Database size is around 750GB.
    Any other information required?
    Last edited by arun4; Mar 16th, 2012 at 06:04 AM.
    Thanks & Regards,
    Arun Duraisamy

  4. #4

    Default

    I think what is happening is that One thread is already closing the connection without notifying others and the second thread comes in and tries to close the connection again. As the connection is already closed it bombs out.

    As I said before I am pretty sure a synchronized delegate with saveState =false is goign to solve the problem.
    saveState =false will help since then the reader is not going to try to save the read counts which is also not synchronized

  5. #5

    Default

    Thanks for your reply sambaran.
    We have started testing with synchronized delegate. Once done, we will update you.
    Thanks & Regards,
    Arun Duraisamy

  6. #6

    Default

    Thanks for your reply Sambaran.
    We are using default HibernateCursorItemReader. I have verified the data. There is to scenario's
    1. Some time Job is completed successfully and data also proper but exception we are getting in logs.
    nice information

  7. #7

    Default

    Hi Sambaran,
    We have tested with the synchronized delegate. we are getting same exception in the
    my.application.batch.core.reader.SynchronizedItemR eader.close(SynchronizedItemReader.java:54).

    Please find the SynchronizedItemReader for your reference.
    Code:
    ublic class SynchronizedItemReader <T> implements ItemReader <T>, ItemStream {
       
        /** The delegate. */
        private ItemReader <T> delegate;
       
        /**
         * Read.
         *
         * @throws Exception
         *             the Exception
         * @return T domain object
         */
        public synchronized T read() throws Exception {
    
            return delegate.read();
        }
       
        /**
         * setDelegate.
         *
         * @param delegate
         *            the item reader
         */
       
        public void setDelegate(ItemReader <T> delegate) {
    
            this.delegate = delegate;
        }
       
        /**
         * close.
         *
         */
        public void close() {
    
            if (this.delegate instanceof ItemStream) {
                ((ItemStream) this.delegate).close();
            }
        }
       
        /**
         * open.
         *
         * @param context
         *            the context
         */
        public void open(ExecutionContext context) {
    
            if (this.delegate instanceof ItemStream) {
                ((ItemStream) this.delegate).open(context);
            }
        }
       
        /**
         * update.
         *
         * @param context
         *            the context
         */
        public void update(ExecutionContext context) {
    
            if (this.delegate instanceof ItemStream) {
                ((ItemStream) this.delegate).update(context);
            }
        }
    }
    Thanks & Regards,
    Arun Duraisamy

  8. #8

    Default

    Did you make sure that you are disabling the savestate (savestate=false) in the reader

  9. #9

    Default

    Please find the SynchronizedItemReader bean code.

    Code:
    	<bean id="commonStepListItemReader"
    		class="my.application.batch.core.reader.SynchronizedItemReader">
    		<property name="delegate" ref="listItemReader" />
    	</bean>
    
    	<bean id="listItemReader"
    		class="org.springframework.batch.item.database.HibernateCursorItemReader"
    		scope="step">
    		<property name="sessionFactory">
    			<ref bean="batchSessionFactory" />
    		</property>
    		<property name="queryString"
    			value="from ListItemDo where listNumber=#{jobParameters['listNumber']} AND statusCode = 0">
    		</property>
    		<property name="saveState" value="false" />
    	</bean>
    Whenever we are getting already closed in the spring batch, we are also getting the JobInterruptedException. Please find the JobInterruptedException.txt attached.
    Already closed and JobInterruptedException occured but batch job is completed. How it is possible? batch job should fail right? Please clarify the same.

    thanks for your reply in advance.
    Attached Files Attached Files
    Last edited by arun4; Mar 27th, 2012 at 01:13 AM.
    Thanks & Regards,
    Arun Duraisamy

  10. #10

    Default

    Are you trying to kill the job execution ..when it is running ?
    When you job execution ran fine...does it mean all data in the databases are proper.did you verify ?
    Also you are adding any debug statement append the current thread name as well...will be a little bit easier to debug.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •