Fórum

Set specific time period for scheduler

thumbnail
Jitendra Rajput, modificado 12 Anos atrás.

Set specific time period for scheduler

Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
Hi All i am currently working with the scheduler provided by liferay.
scheduler is working perfectly fine . but its not satisfying my req.
i want to set a specific time for scheduler like every day scheduler will run on 7 am.


how can i do that ..??
Below is the code that i m currently using.
public class SyncDataJob implements IntervalJob{
	
	public SyncDataJob() {
		
		
		_interval = Time.MINUTE; (Here i want to set my particular time period)
		
	}
	public long getInterval() {
		return _interval;
	}
	
	
	
	
	@Override
	public void execute(com.liferay.portal.kernel.job.JobExecutionContext arg0)
			throws com.liferay.portal.kernel.job.JobExecutionException {
		try {
			System.out.println("THIS IS THE ACTUAL TASK!");
			
		}
		catch (Exception e) {
			_log.error(e);
		}
		
	}
	
	private static Log _log = LogFactory.getLog(SyncDataJob.class);
	private long _interval;




public class Scheduler implements com.liferay.portal.kernel.job.Scheduler {

	public void schedule() {
		
		JobSchedulerUtil.schedule(_testIntervalJob);
	}

	@Override
	public void unschedule() {
		
		JobSchedulerUtil.unschedule(_testIntervalJob);
		
	}
	
	private SyncDataJob _testIntervalJob = new SyncDataJob();
}
thumbnail
Mika Koivisto, modificado 12 Anos atrás.

RE: Set specific time period for scheduler

Liferay Legend Postagens: 1519 Data de Entrada: 07/08/06 Postagens Recentes
If you are using Liferay 6.0+ you could use cron trigger like this:
                <scheduler-entry>
                        <scheduler-event-listener-class>com.liferay.sample.job.SampleJobMessageListener</scheduler-event-listener-class>
                        <trigger>
                                <cron>
                                        <property-key>my.job.cron</property-key>
                                </cron>
                        </trigger>
                </scheduler-entry>


Then in properties you would define:
my.job.cron=0 0 7 * * ?