概述
<bean id="transferInJobProcessor" class="cn.namemax.job.transferin.TransferInJobProcessor"
p:defaultRegistrarId="1" />
public class CdnMessageProcessor implements Runnable {
private static final Log log = LogFactory.getLog(MessageProcessor.class);
private Thread workerThread;
private boolean running = true;
@Override
public void run() {
log.info("Starting cdnMessageProcessor...");
while (running) {
try {
Thread.sleep(60000L);
try {
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
执行方法体;
}
} catch (Exception e) {
log.error(e, e);
} finally {
SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}
} catch (InterruptedException e) {
}
}
log.info("MessageProcessor stopped...");
}
//构造bean后执行的方法,执行后台目标方法(run)
@PostConstruct
public void start() {
workerThread = new Thread(this, "CNNIC_CDN_MessageProcessor");
workerThread.start();
}
@PreDestroy
public void stop() {
log.info("Stopping MessageProcessor...");
running = false;
workerThread.interrupt();
}
}
最后
以上就是淡淡百合为你收集整理的spring 装配bean后执行后台进程任务处理线程的处理方式的全部内容,希望文章能够帮你解决spring 装配bean后执行后台进程任务处理线程的处理方式所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复