`
wezly
  • 浏览: 490425 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

代码发芽网fayaa.com/code/

阅读更多

eg:
package com.neusoft.hnbas.mms.bo;

import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Properties;
import java.util.TimerTask;

import com.neusoft.hnbas.mms.dao.MmsFileDAO;
import com.neusoft.hnbas.mms.vo.MmsVO;

/**
* 发送短信的任务实体
* @author wezly
*
*/
public class MmsTask extends TimerTask {

    public void run() {
        
        System.out.println("-------------task--begin---------------");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
        Calendar now = Calendar.getInstance();// 获取系统时间
        System.out.println("支持任务启动为:" + sdf.format(now.getTime()));

        try {
            
            // 每次任务动态读取属性文件到属性容器
            MmsVO mmsObj = MmsFileDAO.getMmsVO();
            if(mmsObj==null{
                System.out.println("定时为["+now.getTime()+"]的发送彩信任务执行失败.");
                return;
            }
            
            //构建彩信发送代理实体
            MmsSender mmsSender = new MmsSender(mmsObj);

            long begin = System.currentTimeMillis();
            mmsSender.sendMessage(); // 发送短信
            long end = System.currentTimeMillis();
            System.out.println("彩信发送用时:" + ((end - begin/ 1000+ "s");
            //------把发送成功的彩信文件移到配置的文件夹内
            String fileName = MmscConf.getContentFile();
            File file = new File(MmscConf.getCachePath()+fileName);
            File newPath = new File(MmscConf.getOldPath());
            File newFile = new File(MmscConf.getOldPath()+fileName);
            if(!newPath.exists()) {
                newPath.mkdirs();
            }
            file.renameTo(newFile);
        } catch (Exception e{
            System.out.println("执行定时发送任务失败!" );
            e.printStackTrace();
        } finally {
            System.out.println("-------------task--end-----------------");
        }
        
    }
    
    

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics