You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by yanshaozhiGmail <ya...@gmail.com> on 2009/02/04 07:44:42 UTC

How to use job (timing task) in sling

Hi everyone:

I found sling handles jobs base on Quartz however I didn't use it before ,  as a result it's a little difficult for me to grasp it in short time . 
And can anyone tell me how to use it even a simple example such as print a "hello" per 5 minutes ?
Thanks .

2009-02-04 



yanjie 

Re: How to use job (timing task) in sling

Posted by Carsten Ziegeler <cz...@apache.org>.
yanshaozhiGmail wrote:
> Hi everyone:
> 
> I found sling handles jobs base on Quartz however I didn't use it before ,  as a result it's a little difficult for me to grasp it in short time . 
> And can anyone tell me how to use it even a simple example such as print a "hello" per 5 minutes ?
> Thanks .
What do you want to do? Schedule something periodically or at given time?
First, you need the commons scheduler bundle of course. The easiest way
to schedule something is to register a service with OSGi which
implements the java.lang.Runnable interface and has a configuration
property to specify how to schedule this service.
For example if you use SCR with the maven scr plugin:
/**
 * @scr.component
 * @scr.service interface="java.lang.Runnable"
 * @scr.property name="scheduler.period" value="300" type="Long"
*/
public class MyClass implements Runnable {
    public void run() {
        System.out.println("Hello World!");
    }
}

You can either run the job periodically like in the example above
or specify the "scheduler.expression" property with a cron expression.

If you need more control, you can use the
org.apache.sling.commons.scheduler.Scheduler service to add and remove jobs.

HTH
Carsten
-- 
Carsten Ziegeler
cziegeler@apache.org