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
Scheduled Job to check Dates
I have a Maven Project in Liferay Portal 6.2.I have the following table:
There is a requirement where, once per day (let's say at 00:00), a scheduled job must run where it'll check the
I have added this on
Any help is really appreciated.Thank you in advance.
CREATE TABLE DISCIPLINARYAUDIT
(
DISCIPLINARYAUDITID NUMBER(19, 0) NOT NULL
, DISCIPLINARYAUDITTYPE VARCHAR2(255 CHAR) NOT NULL
, REVOCATIONORCOMPLETION NUMBER(1, 0)
, STARTDATE DATE
, ENDDATE DATE
)
There is a requirement where, once per day (let's say at 00:00), a scheduled job must run where it'll check the
ENDDATE
with the current Date. If they are equal, then REVOCATIONORCOMPLETION
must change from 0 to 1.I have added this on
liferay-portlet.xml
: <portlet>
<portlet-name>penaltysearch</portlet-name>
<scheduler-entry>
<scheduler-event-listener-class>gr.yptp.hcg.pen.Utils.PenaltySearchUtil</scheduler-event-listener-class>
<trigger>
<cron>
<!-- Fire at 00:00 every day -->
<cron-trigger-value>0 0 0 1/1 * ? *</cron-trigger-value>
</cron>
</trigger>
</scheduler-entry>
</portlet>
But I am having a hard time implementing the listener where the check is going to be made.Any help is really appreciated.Thank you in advance.
Creating a scheduler should be possible. What are your questions? What problems do you have? If you give more information on the concrete problems it may be easier to help you.
I don't know exactly how to continue with the listener.
You have to implement a MessageListener class. So your gr.yptp.hcg.pen.Utils.PenaltySearchUti should implement MessageListener or extend BaseMessageListener. Everytime the scheduled time is reached the (do)receive-Method is called.
Example from the Liferay 6.2 source code: https://github.com/liferay/liferay-portal/blob/6.2.x/portal-impl/src/com/liferay/portlet/journal/messaging/CheckArticleMessageListener.java
Example from the Liferay 6.2 source code: https://github.com/liferay/liferay-portal/blob/6.2.x/portal-impl/src/com/liferay/portlet/journal/messaging/CheckArticleMessageListener.java
I have the following implementation of the listener:
And I get this on tomcat:
2020-06-05 14:20:00,021 INFO (gr.yptp.hcg.pen.Utils.PenaltySearchUtil.java:29).receive - Scheduler for checking dates on Penalties has started...
14:20:00,021 ERROR [liferay/scheduler_dispatch-1][ParallelDestination:74] Unable to process message {destinationName=liferay/scheduler_dispatch, response=null, responseDestinationName=null, responseId=null, payload=null, values={GROUP_NAME=gr.yptp.hcg.pen.Utils.PenaltySearchUtil, PORTLET_ID=penaltysearch_WAR_hcgshipboatcompanyportlet, companyId=0, MESSAGE_LISTENER_UUID=2e03fb6b-7ef0-4df5-b498-a0402eae6efa, groupId=0, DESTINATION_NAME=liferay/scheduler_dispatch, MESSAGE_LISTENER_CLASS_NAME=gr.yptp.hcg.pen.Utils.PenaltySearchUtil, EXCEPTIONS_MAX_SIZE=0, JOB_STATE=com.liferay.portal.kernel.scheduler.JobState@2808fcf8, RECEIVER_KEY=com.liferay.portal.kernel.scheduler.messaging.ReceiverKey@b2c8a854, STORAGE_TYPE=MEMORY_CLUSTERED, JOB_NAME=gr.yptp.hcg.pen.Utils.PenaltySearchUtil}}
com.liferay.portal.kernel.messaging.MessageListenerException: java.lang.NullPointerException
at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:86)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:72)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:71)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at gr.yptp.hcg.pen.Utils.PenaltySearchUtil.receive(PenaltySearchUtil.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at com.sun.proxy.$Proxy1701.receive(Unknown Source)
at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:77)
... 5 more
If you can help me understand what I am doing wrong, I would really appreciate it.
@Override
public void receive(Message message) throws MessageListenerException {
logger.info("Scheduler for checking dates on Penalties has started...");
Date currentDate = new Date();
List<penalty> penalties = service.findAll();
for (Penalty penalty : penalties) {
if (penalty.endDate == null) {
System.out.println("This date is null");
}
else if (currentDate.after(penalty.endDate)) {
penalty.setRevocationOrCompletion(true);
}
}
}</penalty>
And I get this on tomcat:
2020-06-05 14:20:00,021 INFO (gr.yptp.hcg.pen.Utils.PenaltySearchUtil.java:29).receive - Scheduler for checking dates on Penalties has started...
14:20:00,021 ERROR [liferay/scheduler_dispatch-1][ParallelDestination:74] Unable to process message {destinationName=liferay/scheduler_dispatch, response=null, responseDestinationName=null, responseId=null, payload=null, values={GROUP_NAME=gr.yptp.hcg.pen.Utils.PenaltySearchUtil, PORTLET_ID=penaltysearch_WAR_hcgshipboatcompanyportlet, companyId=0, MESSAGE_LISTENER_UUID=2e03fb6b-7ef0-4df5-b498-a0402eae6efa, groupId=0, DESTINATION_NAME=liferay/scheduler_dispatch, MESSAGE_LISTENER_CLASS_NAME=gr.yptp.hcg.pen.Utils.PenaltySearchUtil, EXCEPTIONS_MAX_SIZE=0, JOB_STATE=com.liferay.portal.kernel.scheduler.JobState@2808fcf8, RECEIVER_KEY=com.liferay.portal.kernel.scheduler.messaging.ReceiverKey@b2c8a854, STORAGE_TYPE=MEMORY_CLUSTERED, JOB_NAME=gr.yptp.hcg.pen.Utils.PenaltySearchUtil}}
com.liferay.portal.kernel.messaging.MessageListenerException: java.lang.NullPointerException
at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:86)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:72)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:71)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at gr.yptp.hcg.pen.Utils.PenaltySearchUtil.receive(PenaltySearchUtil.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at com.sun.proxy.$Proxy1701.receive(Unknown Source)
at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:77)
... 5 more
If you can help me understand what I am doing wrong, I would really appreciate it.
Maybe you can post the whole class, so that I can see what's on line 34 of the class? Something at that line seems to be null.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™