javaWeb SSH 设置后台自启线程,一般用于系统的自主更新

javaWeb  SSH 设置后台自启线程,一般用于系统的自主更新

 

XML写法:


 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">


 
  
  
   
    
   

  

 

 
  
  
  
 

 
  
   
    
   

  

 

 

 

类文件:

package com.lesport.tools;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.lesport.service.AdminService;
import com.lesport.service.impl.AdminServiceImpl;
import com.opensymphony.xwork2.ActionContext;

/**
 * 线程类
 * @author Administrator
 *
 */
public class TimesThread extends QuartzJobBean{
 @Resource
 private AdminService adminService;
 
 private int timeout=0;
 private WebApplicationContext app;
 
 //调度工厂实例化后,经过timeout时间开始执行调度 
 public void setTimeout(int timeout) { 
 this.timeout = timeout; 
 } 
 //初始化
 public void init(){
  app = ContextLoader.getCurrentWebApplicationContext();
 }

 //任务调用
 @Override
 protected void executeInternal(JobExecutionContext arg0)
   throws JobExecutionException {
  init();
  try {
   
   System.out.println("实例数量:"+app.getBeanDefinitionCount());
   System.out.println("定时任务执行中…"); 
   adminService=(AdminService) app.getBean(AdminService.class);
   adminService.Updata_MapData();//自动更新约战信息是否有效adminService.Updata_OPearLeveling();
   adminService.Updata_OPearLeveling();
  } catch (Exception e) {
   e.printStackTrace();
  }
  
 }
}

你可能感兴趣的:(javaWeb SSH 设置后台自启线程,一般用于系统的自主更新)