{"id":2539,"date":"2012-11-02T10:42:00","date_gmt":"2012-11-02T15:42:00","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=2539"},"modified":"2012-11-04T09:58:21","modified_gmt":"2012-11-04T14:58:21","slug":"atg-scheduler-job-example","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2012\/11\/02\/atg-scheduler-job-example\/","title":{"rendered":"ATG scheduler job example"},"content":{"rendered":"<p>ATG supplies a scheduler of sorts that can be used to run tasks that are supposed to run on a recurring basis.<\/p>\n<p>First, cd to your ATG installation directory, and set your CLASSPATH so that the compiler can find the needed ATG components against which to compile our test code.<\/p>\n<pre lang=\"text\">\r\ncd \/root\/ATG\/ATG10.0.3 #or wherever yours is located\r\nexport CLASSPATH=.:$(pwd)\/Initial\/lib\/classes.jar\r\n<\/pre>\n<p>Using the example code from Oracle, we can compile the java class below.  Create the HelloWorld.java file in $ATG_INSTALL_DIR\/home\/locallib<\/p>\n<pre lang=\"java\" line=\"1\">\r\nimport atg.nucleus.*;\r\nimport atg.service.scheduler.*;\r\n\r\npublic class HelloJob extends GenericService implements Schedulable {\r\n  public HelloJob () {}\r\n\r\n  Scheduler scheduler;\r\n  public Scheduler getScheduler () { \r\n    return scheduler; \r\n  }  \r\n  \r\n  public void setScheduler (Scheduler scheduler)  { \r\n    this.scheduler = scheduler; \r\n  }\r\n\r\n  Schedule schedule;\r\n\r\n  public Schedule getSchedule () { \r\n    return schedule; \r\n  }\r\n\r\n  public void setSchedule (Schedule schedule) { \r\n    this.schedule = schedule; \r\n  }\r\n\r\n  public void performScheduledTask (Scheduler scheduler,\r\n                                    ScheduledJob job) { \r\n    System.out.println (\"Hello\"); \r\n  }\r\n\r\n  int jobId;\r\n\r\n  public void doStartService () throws ServiceException {\r\n    ScheduledJob job = new ScheduledJob (\"hello\",\r\n                                         \"Prints Hello\",\r\n                                         getAbsoluteName (),\r\n                                         getSchedule (),\r\n                                         this,\r\n                                         ScheduledJob.SCHEDULER_THREAD);\r\n    jobId = getScheduler ().addScheduledJob (job);\r\n  }\r\n\r\n  public void doStopService () throws ServiceException {\r\n    getScheduler ().removeScheduledJob (jobId);\r\n  }\r\n}\r\n<\/pre>\n<p>Create a properties file for our component with the contents below.  This should be created in $ATG_INSTALL_DIR\/home\/localconfig\/test and be called HelloJob.properties<\/p>\n<pre lang=\"text\">\r\n$class=HelloJob\r\n$scope=global\r\nscheduler=\/atg\/dynamo\/service\/Scheduler\r\nschedule=every 1 minutes\r\n<\/pre>\n<p>If it doesn\u2019t exist, create a file name Initial.properties in your $ATG_INSTALL_DIR\/home\/localconfig directory.<\/p>\n<p>The Oracle example code is incorrect.  The contents of the file should look similar to what is below<\/p>\n<pre lang=\"text\">\r\ninitialServices+=\/test\/HelloJob\r\n<\/pre>\n<p>Copy the HelloJob.class from $ATG_INSTALL_DIR\/home\/locallib to $JBOSS_DIR\/server\/yourappname\/deploy\/yourearfilename.ear\/atglib\/_atghome_slocallib<\/p>\n<p>Restart the JBOSS server.  We should see the job being executed every minute, which you can verify in the dynamo admin web interface located at http:\/\/hostname:port\/dyn\/admin\/nucleus\/atg\/dynamo\/service\/Scheduler\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ATG supplies a scheduler of sorts that can be used to run tasks that are supposed to run on a recurring basis. First, cd to your ATG installation directory, and set your CLASSPATH so that the compiler can find the&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2012\/11\/02\/atg-scheduler-job-example\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[37,38],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2539"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2539"}],"version-history":[{"count":8,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2539\/revisions"}],"predecessor-version":[{"id":2547,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2539\/revisions\/2547"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2539"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}