Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Failure obtaining db row lock exception while integrating spring with Quartz scheduler

Posted on 2006-03-24
19
Medium Priority
?
3,970 Views
Last Modified: 2008-01-09
i am trying to run jobs using quartz(i am using 1.5.1 version) ;quartz scheduler integrated with Spring framework.i am getting exception

org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: ORA-00942: table or view does not exist
 [See nested exception: java.sql.SQLException: ORA-00942: table or view does not exist
]




<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><!--
  - Application context definition for "springapp" DispatcherServlet.
  -->

<beans>

<bean id="myDataSourceTarget" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@xxxxxxx:xxx</value></property>
<property name="username"><value>xxx</value></property>
<property name="password"><value>xxx</value></property>
</bean>
<!--  Often you just need to invoke a method on a specific object. Using the MethodInvokingJobDetailFactoryBean you can do exactly this
-->
<bean id="exampleJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="exampleBusinessObject"/>
<property name="targetMethod" value="doIt"/>
</bean>

<bean id="exampleBusinessObject" class="bus.ExampleJob"/>



<!--
<bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass" value="bus.ExampleJob"/>
  <property name="jobDataAsMap">
    <map>
      <entry key="timeout" value="5"/>
    </map>
  </property>
</bean>
-->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="autoStartup">
      <value>false</value>
    </property>
<property name="dataSource">
                  <ref bean="myDataSourceTarget" />
</property>
<property name="triggers">
    <list>
      <ref bean="cronTrigger"/>
    </list>
  </property>
<property name="applicationContextSchedulerContextKey"><value>applicationContext</value></property>
<property name="waitForJobsToCompleteOnShutdown"><value>true</value></property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.threadPool.threadCount">10</prop>
<prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.OracleDelegate</prop>
<prop key="org.quartz.jobStore.selectWithLockSQL"> SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?</prop>
</props>
</property>

 
</bean>

<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
  <!-- see the example of method invoking job above -->
  <property name="jobDetail" ref="exampleJob"/>
      <!-- 10 seconds -->
  <property name="startDelay" value="10000"/>
      <!-- repeat every 50 seconds -->
  <property name="repeatInterval" value="50000"/>
</bean>


<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
  <property name="jobDetail" ref="exampleJob"/>
      <!-- run every morning at 6 AM -->
  <property name="cronExpression" value="0 0 6 * * ?"/>
</bean>



</beans>
0
Comment
Question by:chaitu chaitu
  • 8
  • 6
  • 5
19 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16287079
>>SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?

Make sure the query produced selects a valid table or view and that it's accessible under the account from which it's being run
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16287092
what's this query actually do
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16287107
No idea - i'd guess it's to do with synching jobs.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 92

Expert Comment

by:objects
ID: 16287554
you don't have a table named QRTZ_LOCKS in your database
0
 
LVL 92

Expert Comment

by:objects
ID: 16287580
do you have perms for that data store to create tables
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16287590
i created all these tables;

qrtz_job_listeners;                                          
qrtz_trigger_listeners;                                      
qrtz_fired_triggers;                                          
qrtz_simple_triggers;                                        
qrtz_cron_triggers;                                          
qrtz_blob_triggers;                                          
qrtz_triggers;                                                
qrtz_job_details;                                            
qrtz_calendars;                                              
qrtz_paused_trigger_grps;                                    
qrtz_locks;                                                  
qrtz_scheduler_state;              

do i need this one in configuartion file;                          

<prop key="org.quartz.jobStore.selectWithLockSQL"> SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?</prop>

0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16287591
after creating above table do i need this query( SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?)
0
 
LVL 92

Expert Comment

by:objects
ID: 16287599
> do i need this one in configuartion file;                          

Sorry I'm not an oracle person, the default query is:

SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16287631
now i am getting this exception

Initialization of bean failed; nested exception is org.quartz.JobPersistenceException: Couldn't store job: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
org.quartz.JobPersistenceException: Couldn't store job: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean [See nested exception: java.io.NotSerializableException: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean]
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16287689
>>MethodInvokingJobDetailFactoryBean

Please post the above
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16287694
2006-03-25 15:47:10,882 ERROR [org.springframework.web.servlet.DispatcherServlet] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Initialization of bean failed; nested exception is org.quartz.JobPersistenceException: Couldn't store job: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
org.quartz.JobPersistenceException: Couldn't store job: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean [See nested exception: java.io.NotSerializableException: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean]
      at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeJob(JobStoreSupport.java:849)
      at org.quartz.impl.jdbcjobstore.JobStoreCMT.storeJob(JobStoreCMT.java:309)
      at org.quartz.core.QuartzScheduler.addJob(QuartzScheduler.java:687)
      at org.quartz.impl.StdScheduler.addJob(StdScheduler.java:261)
      at org.springframework.scheduling.quartz.SchedulerFactoryBean.addJobToScheduler(SchedulerFactoryBean.java:754)
      at org.springframework.scheduling.quartz.SchedulerFactoryBean.registerJobsAndTriggers(SchedulerFactoryBean.java:705)
      at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:521)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16287838
(See my last comment)
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16287851
i didnt get u
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16288192
Please post the code
0
 
LVL 92

Expert Comment

by:objects
ID: 16291001
you cannot use that factory bean with a persitenet store, they are not compatible.
If you weant a persistent job then you need to implement it yourself.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16298130
if u see the SchedulerFactoryBean class u can set the Datasource in it;

http://www.springframework.org/docs/api/org/springframework/scheduling/quartz/SchedulerFactoryBean.html


package bus;
import org.springframework.scheduling.quartz.*;
import org.quartz.*;

public class ExampleJob extends QuartzJobBean {

  private int timeout;
 
  /**
   * Setter called after the ExampleJob is instantiated
   * with the value from the JobDetailBean (5)
   */
  public void setTimeout(int timeout) {
    this.timeout = timeout;
  }
 
  protected void executeInternal(JobExecutionContext ctx)
  throws JobExecutionException {

        System.out.println("in....................");
      // do the actual work
  }

  public void doIt() {
    // do the actual work
              System.out.println("doIt...................");

  }

}

in the doIt() method i want to get database connection using JNDI;
0
 
LVL 92

Accepted Solution

by:
objects earned 1500 total points
ID: 16298181
then do the JNDI lookup in your bean (or just give it a DataSource then as a parameter)

0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16298293
i solved the problem like this;Is there any other approach other than this;




public class ExampleJob extends QuartzJobBean {

  private int timeout;
  private  DataSource dataSource;

  /**
   * Setter called after the ExampleJob is instantiated
   * with the value from the JobDetailBean (5)
   */
  public void setTimeout(int timeout) {
    this.timeout = timeout;
  }

    public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
  }

 
  protected void executeInternal(JobExecutionContext ctx)
  throws JobExecutionException {

        System.out.println("in....................");
      // do the actual work
  }

  public void doIt() {
    // do the actual work

      try
        {
       Context ctx = new InitialContext();

      DataSource ds =
            (DataSource)ctx.lookup(
               "java:oraclePool");

        }

        }catch(Exception e) {
      e.printStackTrace();
    }

  }

}


<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><!--
  - Application context definition for "springapp" DispatcherServlet.
  -->

<beans>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName"><value>java:/oraclePool</value></property>
      </bean>
 
<!--  Often you just need to invoke a method on a specific object. Using the MethodInvokingJobDetailFactoryBean you can do exactly this
-->
<bean id="exampleJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="exampleBusinessObject"/>
<property name="targetMethod" value="doIt"/>
</bean>

<bean id="exampleBusinessObject" class="bus.ExampleJob">
<property name="dataSource">
                  <ref bean="dataSource" />
</property>
</bean>


<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">
<property name="triggers">
  <list>
      <ref bean="cronTrigger"/>
      <ref bean="simpleTrigger"/>
    </list>

  </property>

 
</bean>
   
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
  <!-- see the example of method invoking job above -->
  <property name="jobDetail" ref="exampleJob"/>
      <!-- 10 seconds -->
  <property name="startDelay" value="10000"/>
      <!-- repeat every 50 seconds -->
  <property name="repeatInterval" value="50000"/>
</bean>


<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
  <property name="jobDetail" ref="exampleJob"/>
      <!-- run every morning at 6 AM -->
  <property name="cronExpression" value="0 0 6 * * ?"/>
</bean>



</beans>
0
 
LVL 92

Expert Comment

by:objects
ID: 16298351
thats what I just suggested :)
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question