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


    }

  • 相关阅读:
    分页 工具类 前后台代码 Java JavaScript (ajax) 实现 讲解
    java 对小数位的处理 BigDecimal DecimalFormat 常用操作 浅解
    事务 锁 悲观锁 乐观锁 概念 应用场景 使用方式 小记
    多项目使用同一个zookeeper,遇到的坑
    java线程关键字之volatile
    数据库事务
    Web.xml配置详解之context-param
    WINDOWS上KAFKA运行环境安装
    hibernate 之session学习
    windows 安装hadoop
  • 原文地址:https://www.cnblogs.com/huiandong/p/10178214.html
Copyright © 2011-2022 走看看