Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: scheduler module in liferay dxp 7.3
Hi ,
How can I create a scheduler module in liferay dxp 7.3 . Please share link to documentation or an example .
Can you create scheduler class with implements SchedulerEngine ? and then configure the cron expression?
Please pour in your inputs.
Regards,
Prathibha
i want to know it too.
in current, i use BaseMessageListener.
package com.raritan.ci.srg.scheduler;
@Component(immediate = true, property = { "cron.expression=*/5 * * * * ?" },
service = RecordSyncScheduler.class)
public class RecordSyncScheduler extends BaseMessageListener {
private static Log LOGGER = LogFactoryUtil.getLog(RecordSyncScheduler.class);
@Override
protected void doReceive(Message message) throws Exception {
}
@Activate
@Modified
protected void activate(Map<String, Object> properties) throws SchedulerException {
try {
String cronExpression = GetterUtil.getString(properties.get("cron.expression"), "cronExpression");
LOGGER.info(" cronExpression: " + cronExpression);
String listenerClass = getClass().getName();
Trigger jobTrigger = TriggerFactoryUtil.createTrigger(listenerClass, listenerClass, new Date(), null, cronExpression);
SchedulerEntryImpl schedulerEntryImpl = new SchedulerEntryImpl(listenerClass, jobTrigger);
SchedulerEngineHelperUtil.register(this, schedulerEntryImpl, DestinationNames.SCHEDULER_DISPATCH);
} catch (Exception e) {
LOGGER.error(e);
}
}
@Deactivate
protected void deactive() {
SchedulerEngineHelperUtil.unregister(this);
}
}
Hi,
In Liferay 7.4.3.30 i am implemented same way but still added scheduler details in database and it's not running the scheduler based on time scheduler.
Hello, Refer below code:
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.messaging.DestinationNames;
import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.messaging.MessageListener;
import com.liferay.portal.kernel.messaging.MessageListenerException;
import com.liferay.portal.kernel.scheduler.SchedulerEngineHelper;
import com.liferay.portal.kernel.scheduler.SchedulerEntry;
import com.liferay.portal.kernel.scheduler.SchedulerEntryImpl;
import com.liferay.portal.kernel.scheduler.SchedulerException;
import com.liferay.portal.kernel.scheduler.Trigger;
import com.liferay.portal.kernel.scheduler.TriggerFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import java.util.Date;
import java.util.Map;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
@Component( immediate = true,
property = {
"cron.expression=0 0/1 * 1/1 * ? *" //Occurs every minute
},
service = EmailSchedulerPortlet.class
)
public class EmailSchedulerPortlet implements MessageListener {
private final Log logger = LogFactoryUtil.getLog(EmailSchedulerPortlet.class);
@Reference
SchedulerEngineHelper _helper;
@Activate
@Modified
protected void activate(Map<String,Object> properties) throws SchedulerException {
try {
String cronExpression = GetterUtil.getString(properties.get("cron.expression"), "cronExpression");
logger.info(" cronExpression: " + cronExpression);
String listenerClass = getClass().getName();
Trigger jobTrigger = TriggerFactoryUtil.createTrigger(listenerClass, listenerClass, new Date(), null, cronExpression);
SchedulerEntry entry = new SchedulerEntryImpl(listenerClass, jobTrigger);
_helper.register(this, entry, DestinationNames.SCHEDULER_DISPATCH);
} catch (Exception e) {
logger.error(e);
}
}
@Deactivate
protected void deactive() {
_helper.unregister(this);
}
@Override
public void receive(Message arg0) throws MessageListenerException {
logger.info("Hello every minute");
//Your Business logic
}
}
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™