我正在尝试为我的项目需求实现简单的调度程序,我的项目正在使用Adobe AEM
。到目前为止,我浏览了Adobe网站并尝试实现所提供的示例,但是没有一个示例可以更新我的error.log
文件。
package sling.docu.examples;
import com.majesco.logger.service.impl.Logger;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Property;
import com.majesco.dcf.common.util.CommonConstants;
@Component
@Service(value = Runnable.class)
@Property( name = "scheduler.period", longValue = 10)
public class ScheduledPeriodicJob implements Runnable {
Logger logger = new Logger().getInstance(CommonConstants.COMMONSERVICE_MODULE_ID);
public void run() {
logger.debug("#########################################");
logger.debug("*****************************************");
logger.debug("*****************************************");
logger.debug("*****************************************");
logger.debug("******** ScheduledPeriodicJob ***********");
logger.debug("*****************************************");
logger.debug("*****************************************");
logger.debug("*****************************************");
logger.debug("#########################################");
}
}
因此,根据这个,它应该工作
pom.xml
依赖
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.majesco</groupId>
<artifactId>customerportal</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.majesco</groupId>
<artifactId>commonservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>commonservice</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>
<version>3.8.1</version> <scope>test</scope> </dependency> -->
<dependency>
<groupId>com.majesco</groupId>
<artifactId>objectmodel</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.majesco</groupId>
<artifactId>logger</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- Simple Json -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- Hibernate Core API -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.5.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations -->
<!-- <dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.1.Final</version>
</dependency> -->
<!-- postgresql Driver -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
<!-- EHCache Core APIs -->
<!-- <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId>
<version>2.6.9</version> </dependency> -->
<!-- Hibernate EHCache API -->
<!-- <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId>
<version>4.3.5.Final</version> </dependency> -->
<!-- EHCache uses slf4j for logging -->
<!-- <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId>
<version>1.7.5</version> </dependency> -->
<!-- @log4j2 xml dependency -->
<!-- <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId>
<version>2.0</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <version>2.0</version> </dependency> -->
<!-- javax.mail dependency -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<!-- slf4j-api dependency -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<!-- slf4j-simple dependency -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
</dependency>
<!-- pgichecksum dependency -->
<dependency>
<groupId>com.billdesk.pgidsk</groupId>
<artifactId>pgichecksum</artifactId>
<version>1.0</version>
</dependency>
<!-- esbservicesclient dependency -->
<dependency>
<groupId>esbservices_client</groupId>
<artifactId>esbservicesclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbpolicysearchclient dependency -->
<dependency>
<groupId>esbpolicysearch_client</groupId>
<artifactId>esbpolicysearchclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbcustomerserviceclient dependency -->
<dependency>
<groupId>esbcustomerservice_client</groupId>
<artifactId>esbcustomerserviceclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbcustomerserviceclient dependency -->
<dependency>
<groupId>esbaccountservice_client</groupId>
<artifactId>esbaccountserviceclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbgenericserviceclient dependency -->
<dependency>
<groupId>esbgenericservice_client</groupId>
<artifactId>esbgenericserviceclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbgenericintegrationclient dependency -->
<dependency>
<groupId>genericintegration_client</groupId>
<artifactId>esbgenericintegrationclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- Start pooja added 040817-->
<dependency>
<groupId>esbusermanagement_client</groupId>
<artifactId>esbusermanagementclient</artifactId>
<version>0.0.1-SNAPSHOT </version>
</dependency>
<!-- End pooja added 040817-->
<!-- Start pooja added 050917-->
<dependency>
<groupId>esbrenewalstatus_client</groupId>
<artifactId>esbrenewalstatusclient</artifactId>
<version>0.0.1-SNAPSHOT </version>
</dependency>
<!-- End pooja added 050917-->
<!-- updateCustomerService<07062018> dependency -->
<dependency>
<groupId>esbupdatecustomer_service</groupId>
<artifactId>esbupdatecustomerservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- updateCustomerService<07062018> dependency -->
<!-- esbdatabasefetchservice dependency -->
<dependency>
<groupId>esbdatabasefetchservice_client</groupId>
<artifactId>esbdatabasefetchservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbdatabasefetchservice dependency -->
<!-- base64 commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>5.0.0</version>
</dependency>
<!-- Added for send email functionality -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<!-- 1574973 start -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<!-- 1574973 end -->
</dependencies>
<build>
<resources>
<!-- standard Maven folder -->
<resource>
<directory>src/main/resources</directory>
</resource>
<!-- plus root folder -->
<resource>
<directory>.</directory>
<includes>
<include>plugin.xml</include>
<include>META-INF/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<configuration>
<unpackBundle>true</unpackBundle>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<!-- <Export-Package>com.majesco.portal.service.*;version=${project.version}</Export-Package> -->
<!-- <Import-Package>*</Import-Package> -->
<!-- <Import-Package>!*</Import-Package> <Embed-Dependency>*</Embed-Dependency>
<Bundle-ClassPath>.</Bundle-ClassPath> -->
<!-- <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy> -->
<!-- <Embed-Dependency>*</Embed-Dependency> -->
<Embed-Dependency>!objectmodel,*</Embed-Dependency>
<Export-Package>com.majesco.dcf.common.*,com.majesco.dcf.pg.*,com.majesco.dcf.receipt.*,com.unotechsoft.stub.*,stub.unotechsoft.com.wsdl*,org.apache.http.impl.client*,org.apache.http.ssl*,org.apache.http*,org.apache*,org.datacontract.schemas*</Export-Package>
<Import-Package>org.osgi.framework,org.hibernate.*,com.majesco.dcf.pa.json,org.json.*,*;resolution:=optional</Import-Package>
<!-- <Export-Package>${export.packages}</Export-Package> -->
<!-- <Export-Package>!com.majesco.service.activator,com.majesco.service.*;version=${project.version}</Export-Package> -->
<Bundle-Activator>com.majesco.dcf.common.service.activator.CommonServiceBundleActivator</Bundle-Activator>
</instructions>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<excludePackageNames>com.majesco.dcf.common.util*,com.majesco.dcf.common.service.activator*,com.majesco.dcf.common.entity*,com.majesco.dcf.common.service.impl*,com.majesco.dcf.pg.entity*,com.majesco.dcf.pg.service*,com.majesco.dcf.pg.util*,com.majesco.dcf.pg.billdesk.impl*,com.majesco.dcf.receipt.util*</excludePackageNames>
</configuration>
</plugin>
</plugins>
</build>
</project>
我是否需要进行其他任何更改才能使调度程序正常工作?请建议缺少的内容。
以下解决方案按要求工作,这里处理了三种情况
addJob()
:每分钟执行一次作业addPeriodicJob()
:每3分钟执行一次作业with fireJobAt()
:在特定日期(部署日期+延迟30秒)执行作业
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.commons.scheduler.Scheduler;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
public class ScheduledPeriodicJob {
/* Default log. /
protected final Logger log = LoggerFactory.getLogger(this.getClass());
/* The scheduler for rescheduling jobs. /
@Reference
private Scheduler scheduler;
protected void activate(ComponentContext componentContext) throws Exception {
//case 1: with addJob() method: executes the job every minute
String schedulingExpression = “0 * * ?”;
String jobName1 = “case1”;
Map
boolean canRunConcurrently = true;
final Runnable job1 = new Runnable() {
public void run() {
log.info(“\n\nExecuting”);
log.info(“\n\nExecuting”);
log.info(“\n\nExecuting”);
log.info(“\n\nExecuting”);
log.info(“\n\nExecuting”);
log.info(“\n\nExecuting”);
log.info(“\n\nExecuting”);
log.info(“\n\nExecuting”);
log.info(“\n\nExecuting”);
}
};
try {
this.scheduler.addJob(jobName1, job1, config1, schedulingExpression, canRunConcurrently);
} catch (Exception e) {
job1.run();
}
//case 2: with addPeriodicJob(): executes the job every 3 minutes
String jobName2 = "case2";
long period = 180;
Map<String, Serializable> config2 = new HashMap<String, Serializable>();
final Runnable job2 = new Runnable() {
public void run() {
log.info("\nExecuting 2");
log.info("\nExecuting 2");
log.info("\nExecuting 2");
log.info("\nExecuting 2");
log.info("\nExecuting 2");
log.info("\nExecuting 2");
log.info("\nExecuting 2");
log.info("\nExecuting 2");
}
};
try {
this.scheduler.addPeriodicJob(jobName2, job2, config2, period, canRunConcurrently);
} catch (Exception e) {
job2.run();
}
//case 3: with fireJobAt(): executes the job at a specific date (date of deployment + delay of 30 seconds)
String jobName3 = "case3";
final long delay = 30*1000;
final Date fireDate = new Date();
fireDate.setTime(System.currentTimeMillis() + delay);
Map<String, Serializable> config3 = new HashMap<String, Serializable>();
final Runnable job3 = new Runnable() {
public void run() {
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
log.info("\nExecuting at date: {} with a delay of: {} seconds", fireDate, delay/1000);
}
};
try {
this.scheduler.fireJobAt(jobName3, job3, config3, fireDate);
} catch (Exception e) {
job3.run();
}
}
protected void deactivate(ComponentContext componentContext) {
log.info(“Deactivateddbye!”);
}
}
下边是 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd ">
<modelVersion>4.0.0</modelVersion>
<!-- ====================================================================== -->
<!-- P A R E N T P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->
<parent>
<groupId>com.adobe.cq</groupId>
<artifactId>schedule</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- ====================================================================== -->
<!-- P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->
<artifactId>schedule-bundle</artifactId>
<packaging>bundle</packaging>
<name>My Project Bundle</name>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.tagic</groupId>
<artifactId>logger</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/logger-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.tagic</groupId>
<artifactId>org.apache.sling.commons.scheduler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/org.apache.sling.commons.scheduler-2.3.3-R1232965.jar</systemPath>
</dependency>
</dependencies>
<!-- ====================================================================== -->
<!-- B U I L D D E F I N I T I O N -->
<!-- ====================================================================== -->
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<executions>
<execution>
<id>generate-scr-descriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>com.adobe.cq.schedule-bundle</Bundle-SymbolicName>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
<configuration>
<slingUrl>http://${crx.host}:${crx.port}/apps/myproject/install</slingUrl>
<usePut>true</usePut>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>
*.impl
</excludePackageNames>
</configuration>
</plugin>
</plugins>
</build>
</project>
相关: 我觉得我错过了什么?
这些是什么,我们应该如何配置它们,以查看它们如何影响应用程序性能? 谢谢!
问题内容: 在Akka文档中指出,如果未配置调度程序,则将使用默认调度程序。默认调度程序的属性是什么,即并行度最小值,并行度因子,并行度最大值等? 问题答案: 默认情况下,提供的调度程序是带有的调度程序,并且默认的并行度值为: 最小并行度: 8 并行因子: 3.0 最大并行度: 64 您可以在文档中看到所有这些信息。 有一个节名为: 参考配置清单 这是配置文件的相关部分(我只删除了注释):
我在IO线程上有一个简单的工作,它正在改变主屏幕壁纸,之后我试图在UI线程上运行一些动画: 但这种方法会导致错误:<代码>java。lang.IllegalStateException:观察者必须从主UI线程订阅,但它是线程[RxCachedThreadScheduler-1,5,main] 我尝试将第二个可观察更改为: 但这于事无补。
我正在做一个项目,我们计划使用WLP (WebSphere liberty)代替传统的WAS。 代码使用 WAS 调度程序来调度活动。 liberty 是否也具有与 WAS 中存在的相同级别的调度程序支持/功能? 如何将调度程序任务从webphere迁移到自由?
我是一个新的Android和工作在这个聊天应用,在那里我想改变一个activity元素基于预定的数据,在预定的确切时间。它不一定要工作时,应用程序或电话关闭,但我想发送通知,以及与更改。有AlarmManager、JobScheduler、Handler、Timer和WorkManager,但我对它们之间的比较感到非常困惑。在这种情况下哪一个是最好的选择?