Announcement Announcement Module
Collapse
No announcement yet.
SchedulerFactoryBean and database concurrency problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SchedulerFactoryBean and database concurrency problem

    Hi,

    Could you help me find the proper way to use hibernate AND spring ??
    i m using scheduler beans of Spring and in the jobs i manage myself the transactions. but sometimes... when i start my application, i get these errors:

    business.CronTaskManager] - <sendAlarms database access error -Retry: 1/1error : java.util.ConcurrentModificationException>
    2009-05-19 23:33:23,219 INFO business.CronTaskManager] - <java.util.ConcurrentModificationException>
    2009-05-19 23:33:23,235 INFO business.CronTaskManager] - <sendAlarms database access error -Retry: 1/1error : java.util.ConcurrentModificationException>
    2009-05-19 23:33:23,235 INFO business.CronTaskManager] - <sendAlarms database access error -Retry: 1/1error : java.util.ConcurrentModificationException>
    2009-05-19 23:33:23,235 INFO business.CronTaskManager] - <java.util.ConcurrentModificationException>
    2009-05-19 23:33:23,235 INFO business.CronTaskManager] - <sendAlarms database access error -Retry: 1/1error : java.util.ConcurrentModificationException>
    2009-05-19 23:33:23,235 INFO business.CronTaskManager] - <java.util.ConcurrentModificationException>
    2009-05-19 23:33:23,235 INFO business.CronTaskManager] - <java.util.ConcurrentModificationException>
    2009-05-19 23:33:23,329 WARN [org.hibernate.util.JDBCExceptionReporter] - <SQL Error: 0, SQLState: 08006>
    2009-05-19 23:33:23,329 ERROR [org.hibernate.util.JDBCExceptionReporter] - <An I/O error occured while sending to the backend.>
    2009-05-19 23:33:23,329 ERROR business.CronTaskManager] - <org.hibernate.exception.JDBCConnectionException : could not execute query>
    2009-05-19 23:33:23,360 WARN [org.hibernate.util.JDBCExceptionReporter] - <SQL Error: 0, SQLState: 08006>
    2009-05-19 23:33:23,391 ERROR [org.hibernate.util.JDBCExceptionReporter] - <An I/O error occured while sending to the backend.>
    2009-05-19 23:33:23,391 INFO business.CronTaskManager] - <sendAlarms database access error -Retry: 1/1error : org.hibernate.exception.JDBCConnectionException: could not execute query>
    2009-05-19 23:33:23,391 INFO business.CronTaskManager] - <org.hibernate.exception.JDBCConnectionException : could not execute query>

    Mon bean.xml:

    Code:
    <bean name="alertingJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    		<property name="jobClass" value="cron.AlertingJob" />
    		<property name="jobDataAsMap">
    			<map>
    				<entry key="alertTimeout" value="1" /> <!-- 1 seconds -->
    			</map>
    		</property>
    	</bean>
    	<bean id="AlertingJobSimpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    		<property name="jobDetail" ref="alertingJob" />
    		<property name="startDelay" value="1000" />
    		<property name="repeatInterval" value="1000" />
    	</bean>
    The job

    Code:
    public void sendAlarms(){
    		int retry_count = 0;
    		boolean retry = true;
    		Session session = null;
    		long millisecondsBeforeSendingAlarm = 40000; // 300 000 = 5 Minutes 
    		
    		Calendar cal = Calendar.getInstance();
    		Date dateTmp = null;
    		
            while(retry){
            	try {
        			
            		session = HibernateUtil.getSessionFactory().openSession();
                    session.beginTransaction();
                    
                    //Get all alarms older than t0 - X milliseconds
                    dateTmp = cal.getTime();
                    dateTmp.setTime(dateTmp.getTime() - millisecondsBeforeSendingAlarm);
                    
                    Criteria alarmCriteria = session.createCriteria(Alarms.class);
                    alarmCriteria.add( Restrictions.le("alarmtime", dateTmp) );
                    alarmCriteria.add( Restrictions.eq("alarmstate", "ON") );
                    
                    List<Alarms> alarmsList = alarmCriteria.list();
    
                    for(Alarms current : alarmsList){
                    	//[sendAlarms] Launch alarm
                    	alertManager.manageAlert(current, current.getAlarmtype());
                    	current.setAlarmstate("OFF");
                    	session.save(current);
                    }
                    
                    session.getTransaction().commit();
                    HibernateUtil.getSessionFactory().close();
                    
                    retry = false;
                    
        		} catch (Exception e) {
        			try {
        				//Second try catch as the rollback could fail as well
        				session.getTransaction().rollback();
    		        } catch (HibernateException e1) {
    		        	logger.debug("Error rolling back transaction");
    		        }
        			if(retry_count < numRetries){
        				retry_count++;
        				logger.info("sendAlarms database access error -Retry: "+retry_count+"/"+numRetries + "error : " + e);
        				logger.info(e);
        			}
        			else{
        				//ERROR RETURN VALUE
        				logger.error(e);
        			}
        		}
            }
    	}
    Last edited by Mime29; May 20th, 2009, 01:27 AM.

  • #2
    It s a very big project so, please, don t ask me to make it from the beginning.
    My actual main question is : Why, if i create transactions in my code as in my sample here, i get database access errors in these schedulers...

    And how can i solve this issue?

    Thank you very much for your help.

    Comment

    Working...
    X