[opencms-dev] ScheduledJob is gone after Tomcat restart

Michael Emmerich m.emmerich at alkacon.com
Thu Feb 17 17:10:13 CET 2011


Felix,

> Hi there,
>
> I have a class to create a scheduled job. Its created normally but after a restart of my tomcat server, the job is gone.
>
> CmsScheduleManager csm = OpenCms.getScheduleManager();
> CmsScheduledJobInfo csji = new CmsScheduledJobInfo();
>
> csji.setCronExpression("* 30 4 * * ?");
> csji.setClassName("my.module.class.ClassName");
> csji.setActive(true);
> csji.setReuseInstance(false);
> csji.setJobName("This is my Job");
>
> // (this.cmsObject is an given CmsObject from within an ActionClass)
> csji.setContextInfo(new CmsContextInfo(this.cmsObject.getRequestContext()));
>
> SortedMap parameters = new TreeMap();
> parameters.put("resourceTypId", this.cmsRes.getTypeId());
> parameters.put("resourcePath", this.resourcePath);
> csji.setParameters(parameters)
>
> csm.scheduleJob(this.cmsObject, csji);
>
>
> The Job works fine till my Tomcat restart :-(
>
> Any ideas?

What you missed is to write back the OpenCms System configuration.
Scheduled jobs are written to the opencms-system.xml, take a look at if 
after you added a scheduled job with the Admin interface.

So you should add

    OpenCms.writeConfiguration(CmsSystemConfiguration.class);

to your code, then your job should be saved as well and will survive a 
tomcat restart.

-- 
Kind Regards,
Michael.

-------------------
Michael Emmerich

Visit OpenCms Days 2011 Conference and Expo
May 9 to May 10 2011 in Cologne, Germany
http://www.opencms-days.org

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org



More information about the opencms-dev mailing list