留言板

To create schedule programmaticaly (Liferay 6.2)

Inga Egorova,修改在7 年前。

To create schedule programmaticaly (Liferay 6.2)

New Member 帖子: 2 加入日期: 16-7-5 最近的帖子
Hello!

I'm trying to create a job programmaticaly by different snippets of code like this:

 SchedulerEntry schedulerEntry = new SchedulerEntryImpl();
        schedulerEntry.setDescription("This is a programatically created process");
        schedulerEntry.setEventListenerClass(MessageListenerImpl.class.getName());
        schedulerEntry.setTimeUnit(TimeUnit.MINUTE);
        schedulerEntry.setTriggerType(TriggerType.SIMPLE);
        schedulerEntry.setTriggerValue(30);

        try {
            SchedulerEngineHelperUtil.schedule(schedulerEntry, StorageType.MEMORY_CLUSTERED,
                    "messageScheduler", 0);
        } catch (SchedulerException e) {

            //_log.warn(e);
        }


or


            Trigger myTrigger=new IntervalTrigger(MessageListenerImpl.class.getName(), MessageListenerImpl.class.getName(),new Date(),1);

            SchedulerEngineHelperUtil.schedule(myTrigger, StorageType.PERSISTED, "", "destination", message, 0);
           

- the last one with configuration added via spring-messaging.xml and web.xml. It works fine - I've tried to send and to receive messages and succeeded.

But I alrways get an error message like this:

[#|2016-09-29T10:22:59.877+0000|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=120;_ThreadName=Thread-2;|10:22:59,876 WARN [liferay/scheduler_engine-1][ProxyMessageListener:81] com.liferay.portal.kernel.scheduler.SchedulerException: Unable to schedule job
com.liferay.portal.kernel.scheduler.SchedulerException: Unable to schedule job
at com.liferay.portal.scheduler.quartz.QuartzSchedulerEngine.schedule(QuartzSchedulerEngine.java:415)
at sun.reflect.GeneratedMethodAccessor125.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.liferay.portal.kernel.messaging.proxy.ProxyRequest.execute(ProxyRequest.java:85)
at com.liferay.portal.kernel.messaging.proxy.ProxyMessageListener.receive(ProxyMessageListener.java:51)
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:745)
Caused by: com.liferay.portal.kernel.scheduler.SchedulerException: Unable to register message listener with name ru.enunion.MessageListenerImpl
at com.liferay.portal.scheduler.quartz.QuartzSchedulerEngine.getMessageListener(QuartzSchedulerEngine.java:605)
at com.liferay.portal.scheduler.quartz.QuartzSchedulerEngine.registerMessageListeners(QuartzSchedulerEngine.java:934)
at com.liferay.portal.scheduler.quartz.QuartzSchedulerEngine.schedule(QuartzSchedulerEngine.java:400)
... 10 more
Caused by: java.lang.ClassNotFoundException: ru.enunion.MessageListenerImpl
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1509)
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
at com.liferay.portal.scheduler.quartz.QuartzSchedulerEngine.getMessageListener(QuartzSchedulerEngine.java:593)
... 12 more


It's really awful and irritative! Could you help me, please?
thumbnail
David H Nebinger,修改在7 年前。

RE: To create schedule programmaticaly (Liferay 6.2)

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
looks like some sort of class loader issue, that when the scheduler is being started the class is not available for instantiation.
Inga Egorova,修改在7 年前。

RE: To create schedule programmaticaly (Liferay 6.2)

New Member 帖子: 2 加入日期: 16-7-5 最近的帖子
Doing the same things by configuration file works.

<scheduler-entry>
			<scheduler-event-listener-class>ru.enunion.MessageListenerImpl</scheduler-event-listener-class>
			<trigger>
				<simple>
					<simple-trigger-value>1</simple-trigger-value>
					<!-- this would be some number,-->
					<!--Based in above configurations scheduler will run in every one minute.-->
					<time-unit>second</time-unit>
					<!-- time unit can be day","hour", "minute", "second", or "week"-->
				</simple>
			</trigger>
		</scheduler-entry>


What's the issue? Any ideas are desireable...
thumbnail
David H Nebinger,修改在7 年前。

RE: To create schedule programmaticaly (Liferay 6.2)

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
So when you use the XML, the class itself is not what is scheduled, there's a Liferay adapter class that knows how to instantiate an instance of ru.enunion.MessageListenerImpl by first adjusting for the different class loader.

When you're adding in programmatically, I don't believe you're getting the adapter and therefore not going to be able to create and invoke your instance.
Mike Hartman,修改在7 年前。

RE: To create schedule programmaticaly (Liferay 6.2)

New Member 发布: 1 加入日期: 16-2-6 最近的帖子
Did you ever figure this out?

I have a portlet that schedules a task using the first method you show above. In all of our 6.2 EE environments this works fine. The task is scheduled, no stack trace, everything runs great.

We're working with Liferay support to troubleshoot a different issue with the task. They spun up a vanilla 6.2 EE instance, deployed our portlet, and get that same stack trace.

Since it works fine for us I don't think there's anything wrong with the actual code.