zoukankan      html  css  js  c++  java
  • java callable

    多线程callable

    package com.bmac.rechar.tdztask;

    import java.io.IOException;
    import java.net.SocketException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.concurrent.Callable;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.Future;

    import org.apache.commons.net.ftp.FTPClient;
    import org.apache.commons.net.ftp.FTPFile;
    import org.apache.commons.net.ftp.FTPListParseEngine;
    import org.apache.commons.net.ftp.FTPReply;


    public class NoZhiFuBao {
    public static void main(String[] args) throws SocketException, IOException {
    //zfb20181206.txt C:huiandongoptweixinmac_collatedestdirzfbfile
    String path="/huiandong/opt/weixin/bmac_collate/destdir/zfbfile/";
    boolean theFileIsExist = theFileIsExists(path,3,11);
    System.out.println(theFileIsExist);


    }

    //调用方法判断是否存在对账记录
    public void rechargeSettlement(String zfb,String wx,String qyd,String ykt){
    int taskSize=4;
    ExecutorService executorService = Executors.newFixedThreadPool(taskSize);


    Callable<String> zfbSettle = new Callable<String>() {
    @Override
    public String call() throws Exception {
    boolean theFileIsExists = theFileIsExists(zfb,3,11);
    if(theFileIsExists){
    return "yes";
    }
    return "no";
    }
    };

    Callable<String> wxSettle = new Callable<String>() {
    @Override
    public String call() throws Exception {
    boolean theFileIsExists = theFileIsExists(zfb,3,11);
    if(theFileIsExists){
    return "yes";
    }
    return "no";
    }
    };

    Callable<String> qydSettle = new Callable<String>() {
    @Override
    public String call() throws Exception {
    boolean theFileIsExists = theFileIsExists(zfb,3,11);
    if(theFileIsExists){
    return "yes";
    }
    return "no";
    }
    };


    Callable<String> yktSettle = new Callable<String>() {
    @Override
    public String call() throws Exception {
    boolean theFileIsExists = theFileIsExists(zfb,3,11);
    if(theFileIsExists){
    return "yes";
    }
    return "no";
    }
    };
    Future<String> zfbExists = executorService.submit(zfbSettle);
    Future<String> wxExists = executorService.submit(wxSettle);
    Future<String> qydExists = executorService.submit(qydSettle);
    Future<String> yktExists = executorService.submit(yktSettle);
    }


    //判断是否包含当日
    static synchronized boolean theFileIsExists(String path,int beginIndex,int endIndex){
    FTPClient ftpClient = new FTPClient();
    try {
    ftpClient.connect("node02");
    ftpClient.setControlEncoding("UTF-8");
    int reply = ftpClient.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
    ftpClient.disconnect();
    }
    ftpClient.login("root","123456");

    FTPFile[] listFiles = ftpClient.listFiles(path);
    if(isExist2(listFiles,3,11)){
    return true;
    }
    } catch (SocketException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    return false;
    }

    static boolean isExist2(FTPFile[] listNames,int beginIndex,int endIndex){
    SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
    Calendar instance = Calendar.getInstance();
    instance.add(Calendar.DATE, -1);
    Date time = instance.getTime();
    for(int i=0;i<listNames.length;i++){
    String date=listNames[i].getName().substring(beginIndex, endIndex);
    if(date!=null && date.equals(sdf.format(time))){
    return true;
    }
    }
    return false;
    }


    }

  • 相关阅读:
    jquery easyui datebox 时间控件默认显示当前日期的实现方法
    CentOS下Web服务器环境搭建LNMP一键安装包
    EasyUI DateBox 按钮自定义添加功能
    Java程序如何生成Jar、exe及安装文件
    推荐!Sublime Text 最佳插件列表
    Sublime Text插件:HTML+CSS+JAVASCRIPT+JSON快速格式化
    java判断是excel2003还是2007以上
    Content-Type: application/vnd.ms-excel"
    小说大纲
    java判断文件真实类型
  • 原文地址:https://www.cnblogs.com/huiandong/p/10178214.html
Copyright © 2011-2022 走看看