Quartz scheduler and OSGI

百般思念 提交于 2019-12-04 15:52:41

Use a real Quartz OSGi bundle, such as the one available here:

http://ebr.springsource.com/repository/app/bundle/detail?name=com.springsource.org.quartz

The latest Quartz version available there is 1.6.2. If you need a newer version, building your own bundle is pretty easy with bnd or bundlor.

Then you can expose StatefulJob as a service anywhere in your OSGi environment, and have your scheduler bundle register and deregister those jobs with Quartz. Even better, have the scheduler bundle listen for any services that are wrappers around your trigger and job information, such as the Spring CronTriggerBean or SimpleTriggerBean. This way,

1) your internal API / OSGi services are not Quartz specific -- only the scheduling bundle has a dependency on the Quartz bundle, and

2) your application bundles can determine the job's schedule instead of the scheduling bundle trying to figure that out.

Update: Newer Quartz OSGi bundles are available from the ServiceMix project: http://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.quartz/

Here you can find newer Quartz OSGI bundles (up to version 2.2.0 at the time of writing):

http://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.quartz

You can install these bundles

bundle:install wrap:mvn:c3p0/c3p0/0.9.1.2
bundle:install mvn:org.quartz-scheduler/quartz/2.2.2
bundle:install wrap:mvn:org.quartz-scheduler/quartz-jobs/2.2.2

You will need these dependency

       <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.quartz</artifactId>
            <version>2.2.2_1</version>
        </dependency>

        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!