7 Replies Latest reply: Aug 14, 2009 11:12 AM by Ronald van Kuijk RSS

    how to start job executor

    blalls asdsd Novice

      How can I start jobExecutor and configure it in jbpm4? Does it starts automatically or should I start manually?

        • 1. Re: how to start job executor
          Yeling Shi Newbie

          I imported the job executor configuration file to the jbpm config.

           <import resource="jbpm.jobexecutor.cfg.xml" />

          but it do not start automatically when the program runs.

          I found the code to start it programmatically from the JobExecutorThread class.

          But, do we have to do this?

          • 2. Re: how to start job executor
            Joram Barrez Master

            Adding the import to you jbpm.cfg.xml should do the trick. How are you testing the job executor?

            • 3. Re: how to start job executor
              Yeling Shi Newbie

              I'm using a Java class with a main method to test the job executor.
              I start a thread parse command line from console and invoke jbpm execution services.

              The behavior is:
              Job executor does not start with process engine,
              But when I create new process instance which has timer defined, it starts automatically.

              I looked up the source code, found the problem might be:
              in JbpmConfiguration

              protected WireContext processEngineWireContext = new WireContext(new WireDefinition(), Context.CONTEXTNAME_PROCESS_ENGINE);

              configuration object have a WireContext object created before parsing any configuration, and the WireContext will do:
               fire(EVENT_OPEN, null);

              when it is created. But, at that time, there is not configuration file parsed so eager initialization won't have anything to do.

              When user try to schedule a job( timer) and open a new Environment, the eager initialize method is invoked in runtime.

              Currently we could start the job executor with the servlet or a spring initializing bean.

              • 4. Re: how to start job executor
                Kitanai Newbie

                I'm seeing exactly the same behaviour using this code:

                ProcessEngine processEngine=new Configuration().setResource("my.jbpm.cfg.xml").buildProcessEngine();
                RepositoryService repositoryService = processEngine.getRepositoryService();
                ExecutionService executionService = processEngine.getExecutionService();


                <import resource="jbpm.default.cfg.xml"/>
                <import resource="jbpm.tx.hibernate.cfg.xml"/>
                <import resource="jbpm.jpdl.cfg.xml"/>
                <import resource="jbpm.jobexecutor.cfg.xml" />

                On startup the timers are not fired, however the moment I execute this line of code:

                String id=executionService.startProcessInstanceByKey(workflowName,ParameterHelper.getParameters(parameters)).getId();

                All the timers that were stored up in the DB fire.

                My current nasty hack is to have a dummy with this code (doing one without a timer doesn't work either):

                <process name="Dummy" xmlns="http://jbpm.org/4.0/jpdl">
                <start name="a">
                <transition to="b"/>
                <state name="b">
                <transition to="c" name="toc">
                <timer duedate="1 second" />
                <end name="c"/>

                And the line:


                In the main.

                Does anyone know if we're doing something wrong, or if this should be reported as a bug?


                - Kit

                • 5. Re: how to start job executor
                  Yeling Shi Newbie

                  Instead of starting a dummy workflow, you can tell the jobExecutor to start programatically. The following code is from JobExecutorServlet.

                   EnvironmentFactory environmentFactory = (EnvironmentFactory) new Configuration().setResource(configurationResource).buildProcessEngine();
                   jobExecutor = environmentFactory.get(JobExecutor.class);
                   if (jobExecutor==null) {
                   throw new JbpmException("no job executor configured in resource "+configurationResource);

                  you can do this any where you can get the process engine object.
                  Servlet for web apps or spring initializing bean.

                  • 6. Re: how to start job executor
                    Marcel de Koster Newbie

                    I also added the programmatic timer start using the TaskExecuter via the ProcessEngine interface (you do not need to cast to a specific class).

                    But shouldn't it be possible to do this:

                    <job-executor auto-start="true" />


                    For me the above code doesn't work. Only programmatic starting of job executor.

                    • 7. Re: how to start job executor
                      Ronald van Kuijk Master

                      Technically yes (to a certain extend), practically no (due to the limitations of this 'certain extend')

                      Shiyeling menthioned them already: Many usecases of using jBPM in different environments. e.g. you cannot start a thread from a normal class in many appservers, you needs startup servlets for this..