cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Java Scheduler: Can't create task

Former Member
0 Kudos

Hi,

I have following problem:

I created a new job. No problems so far. I can see it in the job definitions and a can create tasks manually in the NW adm.

Now I tried to add a task programmatically.

This is my message driven bean:

@MessageDriven(

                    activationConfig = {

                                        @ActivationConfigProperty(

                                                            propertyName = "messageSelector", propertyValue = "JobDefinition='NewSchedulerJob'"

                                        ),

                                        @ActivationConfigProperty(

                                                            propertyName = "destinationType", propertyValue = "javax.jms.Queue"

                                        ) })

public class SchedulerJobBean extends MDBJobImplementation {

          private static final Location loc = Location.getLocation(Location.getLocation("com.hbas.service.bean"));

 

    public void onJob(JobContext ctx) {

       

              Logger log = ctx.getLogger();

              //Obtain a JNDI reference to the scheduler

              Scheduler scheduler;

              Context init_ctx;

                    try {

                              init_ctx = new InitialContext();

                              scheduler = (Scheduler)init_ctx.lookup("scheduler");

                              SchedulerRemote sessionBeanBean = (SchedulerRemote) init_ctx.lookup("sap.com/some_app/REMOTE/SchedulerBean/some_appRemote");

                        String value = sessionBeanBean.getResult("1234567890");

                        log.info("The status of the unit is: " + value);

              

                    } catch (NamingException e) {

                              e.printStackTrace();

                              return;

                    }

                    //Get the Job definition by name

                    //as defined in the job-definition.xml

                    JobDefinition jobDef = scheduler.getJobDefinitionByName("NewSchedulerJob");

                    // Create SchedulerTime instance for one minute in the future

                    Calendar calendar = Calendar.getInstance();

                    calendar.add(Calendar.MINUTE, 1);

                    Date date = calendar.getTime();

                    //Create SchedulerTime and pass to it the Calendar instance

                    SchedulerTime time = new SchedulerTime(date, TimeZone.getDefault());

                    //Create RecurringEntry and pass to it SchedulerTime instance

                    RecurringEntry[] re = { new RecurringEntry(time) };

                    //Create a SchedulerTask for the Job

                    SchedulerTask task = SchedulerTask.createSchedulerTask(jobDef.getJobDefinitionId(), null, re, null, null, -2, "NewSchedulerJob", "Get the result", null);

                    //Schedule the task

                    try {

                              scheduler.schedule(task);

                    } catch (TaskValidationException e) {

                              SimpleLogger.log(Severity.ERROR, Category.SYS_SERVER, loc, "api:ab0200", "Scheduler error " + e );

                              return;

                    }

                    return;

 

    }

And my job-definition

<?xml version="1.0" encoding="UTF-8"?>

<job-definitions>

          <job-definition name="NewSchedulerJob" description="Log and calc string">

          </job-definition>

</job-definitions>

But after the deployment I can't see a new task.

Any suggestions?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

No one?

Former Member
0 Kudos

push