没有真正理解内核,只是模仿使用。
用来定时检验是否为工作日。
applicationContext.xml
<?
xml version="1.0" encoding="UTF-8"
?>
<
beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx=
"http://www.springframework.org/schema/tx"
xsi:schemaLocation=
"
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
>
<!-- cronTrigger extends QuartzJobBean,MyJob1 -->
<bean id="myJob1" class="org.springframework.scheduling.quartz.JobDetailBean"
>
<property name="jobClass" value="com.apple.sqm.dnwd.detect.delta.Detect"
/>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"
>
<property name="jobDetail" ref="myJob1"
/>
<property name="cronExpression" value="0/5 * * * * ?"
/>
</bean
>
<!-- set scheduler -->
<bean id="myScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
>
<property name="triggers"
>
<list
>
<ref bean="cronTrigger"
/>
</list
>
</property
>
<property name="quartzProperties"
>
<props
>
<prop key="org.quartz.threadPool.threadCount">50</prop
>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop
>
</props
>
</property
>
</bean
>
</
beans>
commons-logging.properties
# \u6b64\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u7701\u7565,\u9ed8\u8ba4\u5c31\u662f\u4f7f\u7528\u7684log4j
# \u5fc5\u987b\u8981\u6709commons-logging-1.1.1.jar;
# commons-logging-adapters-1.1.1.jar,commons-logging-api-1.1.1.jar\u4e3a\u53ef\u9009
org.apache.commons.logging.Log=
org.apache.commons.logging.impl.Log4JLogger
log4j.rootLogger=
INFO,appender1
# org.springframework\u5305\u4e0b\u9762\u6240\u6709\u7684\u65e5\u5fd7\u8f93\u51fa\u7684\u7ea7\u522b\u8bbe\u4e3aDEBUG
log4j.logger.org.springframework=
INFO
# \u63a7\u5236\u53f0\u8f93\u51fa
log4j.appender.appender1=
org.apache.log4j.ConsoleAppender
log4j.appender.appender1.layout=
org.apache.log4j.PatternLayout
log4j.appender.appender1.layout.ConversionPattern=
%d{ yyyy-MM-dd HH:mm:ss:SSS}[%p]:
%m%n
# \u7acb\u5373\u8f93\u51fa
log4j.appender.appender1.immediateFlush=
true
package
com.apple.sqm.dnwd;
import
org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
public
classDNWDServer {
/**
*
@param
args
*/
private static Log log = LogFactory.getLog(DNWDServer.class);
public static void main(String[] args) throws Exception {
log.info("Detect non-working-day start");
new ClassPathXmlApplicationContext("applicationContext.xml");
}
}
package
com.apple.sqm.dnwd.detect;
import
org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory;
import
org.quartz.JobExecutionContext;
import
org.quartz.JobExecutionException;
import
org.springframework.scheduling.quartz.QuartzJobBean;
public
abstract class ADetect extends
QuartzJobBean {
Log
log = LogFactory.getLog(ADetect.class
);
protected void executeInternal(JobExecutionContext ctx) throws
JobExecutionException {
extractQuanlity();
}
public abstract void
extractQuanlity();
}
package
com.apple.sqm.dnwd.detect.delta;
import
org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory;
import
com.apple.sqm.dnwd.detect.ADetect;
public
class Detect extends
ADetect{
Log
log = LogFactory.getLog(Detect.class
);
@Override
public void
extractQuanlity() {
log.info("Hello,in detecting"
);
log.info(Detect.class
.getName());
}
}