java笔记

1、线程

protected void process()
{
ExecutorService executorService;
//开10个线程
executorService = Executors.newFixedThreadPool(10);
//来一批数据,提交一个线程
executorService.submit(new Runnable()
{
@Override
public void run()
{
//do something
}
});
}


2、jaxb

public void init() throws Exception
{
InputStream input = this.getClass()
.getClassLoader()
.getResourceAsStream("conf/report.xml");
JAXBContext jc = JAXBContext.newInstance("com.dxy.report.types");
Unmarshaller u = jc.createUnmarshaller();
Reports reports = (Reports) u.unmarshal(input);
List<ReportType> reportList = reports.getReport();
for (ReportType reportType : reportList)
{
reportDefinitions.add(new ReportDefinitionImpl(reportType));
}
}


3、加载配置文件

public static void doTest()
{
ApplicationContext appContext = new ClassPathXmlApplicationContext(
"META-INF/spring/service-context.xml");

A a= (A) appContext.getBean("id");
}


4、xjc工具
xjc.sh -p com.test.type reports.xsd -d work

选项说明:
-p:指定生成的类的包名
-d:指定存放类的目标目录

5、spring定时器:定时执行excute方法

<bean id="report_clearHistory" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<bean
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<bean
class="com.dxy.ftp.CleanHistoryReportFileTimerTask">
<property name="fileAndFtpService" ref="report_FileAndFtpService"></property>
</bean>
</property>
<property name="targetMethod">
<value>execute</value>
</property>
<property name="concurrent" value="false" />
</bean>
</property>
<property name="cronExpression">
<value>${report.localfile.clean.triggerCron}</value>
</property>
</bean>

<bean id="report_schedulerFactory"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
destroy-method="destroy">
<property name="triggers">
<list>

<ref bean="report_clearHistory" />
</list>
</property>
</bean>

<bean id="holder"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath*:conf/timertask.properties</value>
</list>
</property>
</bean>


public void execute()
{
holdingDays = 3;

for (SourceType sourceType : SourceType.values())
{
try
{
fileAndFtpService.clearLocalReportFile(sourceType, holdingDays);
}
catch (ReportException e)
{
//
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值