5 Replies Latest reply on Jun 24, 2008 5:20 PM by csaldanh

    How to programmaticly schedule many tasks ?

    Damien Newbie

      Hi all,

      I was reading many docs and post on scheduling into Jboss and I didn't really found any good solution. I use Jboss 4.05 GA in clustered environnement.

      I need to create and schedule programmaticly each days , at any time, many tasks which require at least one parameter (this parameter can differ and change behavior of tasks)
      I need as I said I use cluster, to execute tasks on only one node into the farm, but I want to register new tasks anywhere in the farm.


      Do I need to register new tasks with only a JMX Schedule Manager ?
      or any other way ?

      As I will register for example 200 tasks by days at any time (these tasks will run once at a given time), do I need to declare only one Scheduler config (org.jboss.varia.scheduler.Scheduler) or one SchedulerProvider config (org.jboss.varia.scheduler.SingleScheduleProvider | org.jboss.varia.scheduler.DBScheduleProvider)?

      I'm completly lost and I need help !!

        • 2. Re: How to programmaticly schedule many tasks ?
          Damien Newbie

          For moment, I've succeed in create one task programmaticly, but :
          - first I add a schedule which must start 30 sec after
          - I stop the server which add schedule
          - I didn't see the schedule started on one other node on my farm (3 servers)

          Did I forgot something ?

          MBeanServer server = MBeanServerLocator.locateJBoss();
           ScheduleManagerMBean schedule = null;
           try {
           ObjectName pProvider = new ObjectName("jboss:service=SingleScheduleProvider");
           ObjectName pTarget = new ObjectName("jboss:service=SchedulableMBeanExample");
           schedule = (ScheduleManagerMBean) MBeanProxyExt.create(ScheduleManagerMBean.class, "jboss:service=ScheduleManager", server);
           String[] params = {"NOTIFICATION", "DATE", "REPETITIONS", "SCHEDULER_NAME", "java.lang.String"};
           Date d = new Date(Calendar.getInstance().getTime().getTime()+30000);
           System.out.println("adding task for "+d);
           schedule.addSchedule(pProvider,pTarget,"hit",params,d,2000,9);
           } catch (Exception e) {
           e.printStackTrace();
           }



          <mbean code="org.jboss.varia.scheduler.SingleScheduleProvider"
           name="jboss:service=SingleScheduleProvider">
           <depends >jboss:service=mypartition</depends>
           <depends>jboss:service=ScheduleManager</depends>
           <depends>jboss:service=SchedulableMBeanExample</depends>
           <depends optional-attribute-name="ScheduleManagerName">jboss:service=ScheduleManager</depends>
           <depends optional-attribute-name="TargetName">jboss:service=SchedulableMBeanExample</depends>
           <depends>jboss.ha:service=HASingletonDeployer,type=Barrier</depends>
           <attribute name="TargetMethod">hit( NOTIFICATION, DATE, REPETITIONS, SCHEDULER_NAME, java.lang.String )</attribute>
           <attribute name="DateFormat"></attribute>
           <attribute name="StartDate"></attribute>
           <attribute name="Period"></attribute>
           <attribute name="Repetitions"></attribute>
           </mbean>
           <mbean code="org.jboss.varia.scheduler.example.SchedulableMBeanExample"
           name="jboss:service=SchedulableMBeanExample">
           </mbean>
           <mbean code="org.jboss.varia.scheduler.ScheduleManager"
           name="jboss:service=ScheduleManager">
           <attribute name="StartAtStartup">true</attribute>
          </mbean>


          • 3. Re: How to programmaticly schedule many tasks ?
            Damien Newbie

            some help will be appreciated ;)

            • 5. Re: How to programmaticly schedule many tasks ?
              csaldanh Newbie

              Came across this link while going through the jboss wiki but haven't tried it yet

              http://wiki.jboss.org/wiki/Scheduler

              Hope it helps