Need to calculate when the next job will be running

Pedro Felgueiras
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2017

Based on a cron expression i need to know when is the next time on job will run. 

 

I had imported the quartz on maven. 

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>

 And have created a simple class with a static method. 

import java.text.ParseException;
import java.util.Date;
import org.quartz.CronExpression;


public class CronUtils {
public static Date nextTime(String frequency) {
try {
return new CronExpression(frequency).getNextValidTimeAfter(new Date());
} catch (ParseException e) {
return null;
}
}
}

The problem is when i try to install the plugin i got this error: 

[INFO] [talledLocalContainer] 2017-08-07 14:54:45,611 QuickReload - Plugin Installer ERROR [c.a.p.osgi.factory.OsgiPluginInstalledHelper] Cannot determine required plugins, cannot resolve bundle 'xxx.xxx.xxx.xxx.xxxxxx'
[INFO] [talledLocalContainer] 2017-08-07 14:54:45,616 QuickReload - Plugin Installer ERROR [c.a.p.osgi.factory.OsgiPlugin] Detected an error (BundleException) enabling the plugin 'xxx.xxx.xxx.xxx.xxxxxx' : Unresolved constraint in bundle xxx.xxx.xxx.xxx.xxxxxx [190]: Unable to resolve 190.0: missing requirement [190.0] osgi.wiring.package; (osgi.wiring.package=org.quartz). This error usually occurs when your plugin imports a package from another bundle with a specific version constraint and either the bundle providing that package doesn't meet those version constraints, or there is no bundle available that provides the specified package. For more details on how to fix this, see https://developer.atlassian.com/x/mQAN
[INFO] [talledLocalContainer] 2017-08-07 14:54:45,616 QuickReload - Plugin Installer WARN [c.a.plugin.impl.AbstractPlugin] Unable to enable plugin 'xxx.xxx.xxx.xxx.xxxxxx'
[INFO] [talledLocalContainer] 2017-08-07 14:54:45,616 QuickReload - Plugin Installer WARN [c.a.plugin.impl.AbstractPlugin] Because of this exception
[INFO] [talledLocalContainer] com.atlassian.plugin.osgi.container.OsgiContainerException: Cannot start plugin: xxx.xxx.xxx.xxx.xxxxxx
[INFO] [talledLocalContainer] at com.atlassian.plugin.osgi.factory.OsgiPlugin.enableInternal(OsgiPlugin.java:418)
[INFO] [talledLocalContainer] at com.atlassian.plugin.impl.AbstractPlugin.enable(AbstractPlugin.java:286)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.PluginEnabler.actualEnable(PluginEnabler.java:130)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.PluginEnabler.enable(PluginEnabler.java:107)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.DefaultPluginManager.enableDependentPlugins(DefaultPluginManager.java:1212)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.DefaultPluginManager.addPlugins(DefaultPluginManager.java:1188)
[INFO] [talledLocalContainer] at com.atlassian.jira.plugin.JiraPluginManager.addPlugins(JiraPluginManager.java:150)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.DefaultPluginManager.scanForNewPlugins(DefaultPluginManager.java:903)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.DefaultPluginManager.installPlugins(DefaultPluginManager.java:821)
[INFO] [talledLocalContainer] at com.atlassian.jira.plugin.JiraPluginManager.installPlugins(JiraPluginManager.java:168)
[INFO] [talledLocalContainer] ... 3 filtered
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:497)
[INFO] [talledLocalContainer] at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
[INFO] [talledLocalContainer] at com.sun.proxy.$Proxy513.installPlugins(Unknown Source)
[INFO] [talledLocalContainer] ... 3 filtered
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:497)
[INFO] [talledLocalContainer] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
[INFO] [talledLocalContainer] at com.sun.proxy.$Proxy867.installPlugins(Unknown Source)
[INFO] [talledLocalContainer] at com.atlassian.labs.plugins.quickreload.install.PluginInstallerMechanic.installPluginImmediately(PluginInstallerMechanic.java:185)
[INFO] [talledLocalContainer] at com.atlassian.labs.plugins.quickreload.install.PluginInstaller.installPluginImmediately(PluginInstaller.java:318)
[INFO] [talledLocalContainer] at com.atlassian.labs.plugins.quickreload.install.PluginInstaller.attemptInstall(PluginInstaller.java:308)
[INFO] [talledLocalContainer] at com.atlassian.labs.plugins.quickreload.install.PluginInstaller.loopWaitingForInstallPromises(PluginInstaller.java:232)
[INFO] [talledLocalContainer] at com.atlassian.labs.plugins.quickreload.install.PluginInstaller.access$000(PluginInstaller.java:36)
[INFO] [talledLocalContainer] at com.atlassian.labs.plugins.quickreload.install.PluginInstaller$1.run(PluginInstaller.java:75)
[INFO] [talledLocalContainer] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[INFO] [talledLocalContainer] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[INFO] [talledLocalContainer] at java.lang.Thread.run(Thread.java:745)
[INFO] [talledLocalContainer] Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle xxx.xxx.xxx.xxx.xxxxxx [190]: Unable to resolve 190.0: missing requirement [190.0] osgi.wiring.package; (osgi.wiring.package=org.quartz)
[INFO] [talledLocalContainer] at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
[INFO] [talledLocalContainer] at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
[INFO] [talledLocalContainer] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
[INFO] [talledLocalContainer] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
[INFO] [talledLocalContainer] at com.atlassian.plugin.osgi.factory.OsgiPlugin.enableInternal(OsgiPlugin.java:399)

 

Any one know what I can do to solve this?

1 answer

1 accepted

0 votes
Answer accepted
Pedro Felgueiras
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 8, 2017

The alternative I had found was to user the cron4j insted of the quartz. 

My class looks like these 

import java.util.Date;
import it.sauronsoftware.cron4j.Predictor;
import it.sauronsoftware.cron4j.SchedulingPattern;


public class CronTools {
public static Date nextRun(SchedulingPattern expression) {
return new Predictor(expression).nextMatchingDate();
}

public static SchedulingPattern parser(String expression) {
return new SchedulingPattern(expression);
}

public static boolean validate(String expression) {
return SchedulingPattern.validate(expression);
}
}

Suggest an answer

Log in or Sign up to answer