Question : Quartz Scheduler to invoke EJB Method

Hi,
    I want to invoke the EJB method using the quartz scheduler when the weblogic server starts up. I am using Weblogic 8.
  If somebody gives me a sample code and tell how to do it, will have a great help to me.


Answer : Quartz Scheduler to invoke EJB Method

You will need several classes.
One is the weblogic startup class, which should look like this:
import weblogic.common.*;
import javax.naming.*;
import com.issw.rules.*;

public class MyT3StartupImpl implements T3StartupDef {
  private T3ServicesDef services;
  public void setServices(T3ServicesDef services) {
    this.services = services;
  }

  public String startup(String name, Hashtable args) throws Exception {
        SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();

        Scheduler sched = schedFact.getScheduler();

        sched.start();

        JobDetail jobDetail = new JobDetail("jobid",
                                            sched.DEFAULT_GROUP,
                                            Demo.class);

        SimpleTrigger trigger = new SimpleTrigger("triggerid",
                                                  sched.DEFAULT_GROUP,
                                                  new Date(),
                                                  null,
                                                  SimpleTrigger.REPEAT_INDEFINITELY,
                                                  1000L);

        sched.scheduleJob(jobDetail, trigger);
 
  }
}


It will create each time an instance of our demo class, which will call the EJB:
import org.quartz.*;

public class Demo implements Job {

    public void execute(JobExecutionContext jec) throws JobExecutionException {
   
          InitialContext ic = new InitialContext();
          MyEJBHome h = ic.lookup("MyEJBName");
          
          // Code to create and access the EJB
    }
}


Note that we do not cache the InitialContext in this example, meaning a new lookup will be done on each execution. You can use the JobDataMap class for storing the InitialContext or the remote interface (use JobDataMap data = jec.getJobDetail().getJobDataMap(); Note that if you do store objects in the JobDataMap object you need to implement StatefulJob instead of the Job interface).

Place both class files in a JAR file, and put it in the WLS classpath. Configure the startup class in the WLS console, and that should be it.
Random Solutions  
 
programming4us programming4us