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;
    }


    }

  • 相关阅读:
    python测试开发django177.启动项目添加初始化数据(fixtures的使用) 上海
    python笔记70 Python中`__repr__`和`__str__`区别 上海
    python笔记69 什么是猴子补丁(Monkey Patch)? 上海
    pytest文档78 钩子函数pytest_runtest_makereport获取用例执行报错内容和print内容 上海
    python测试开发django176.数据库迁移数据(manage.py dumpdata) 上海
    python3面试题:如何用python实现栈(Stack)的操作? 上海
    python笔记71 traceback.print_exc()保存异常内容 上海
    测试驱动开发 Rss Reader Item Marker
    Rhino Mocks (RhinoMock)2
    继承的Singleton模式的实现
  • 原文地址:https://www.cnblogs.com/huiandong/p/10178214.html
Copyright © 2011-2022 走看看