java大数据处理(千万级别FTP下载)

欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入

  if(lff.getIsFileExists(file)){//判断本地文件是否存在,如果存在并且长度小于FTP文件的长度时断点续传;返之新增  long size = this.getSize(pathName);  long localFileSize = lff.getSize(file);  if(localFileSize > size){  return false;  }  out = new FileOutputStream(file,true);  client.setRestartOffset(localFileSize);  flag = client.retrieveFile(new String(pathName.getBytes(),client.getControlEncoding()),out);  out.flush();  } else{  out = new FileOutputStream(file);  flag = client.retrieveFile(new String(pathName.getBytes(),client.getControlEncoding()),out);  out.flush();  }  }catch(IOException e){  log.error(e);  log.error(”file download error !”);  throw e;  }finally{  try{  if(null!=out)  out.close();  if(flag)  lff.rename(file, localPath);  }catch(IOException e){  throw e;  }  }  return flag;  }  /**  * 获取文件长度  * @param fileNamepath 本机文件  * @return  * @throws IOException  */  public long getSize(String fileNamepath) throws IOException{  FTPFile [] ftp = client.listFiles(new String(fileNamepath.getBytes(),client.getControlEncoding()));  return ftp.length==0 ? 0 : ftp[0].getSize();  }  检测本地文件是否已经下载,如果下载文件的大小。  /**  *本地文件的 获取文件的大小  * @param file  * @return  */  public long getSize(File file){  long size = 0;  if(getIsFileExists(file)){  size = file.length();  }  return size;  }  5、因为程序要跑最多100多个线程,在线程监控上做了一些处理,可以检测那些死掉的线程,并及时的拉起来。  t.setUncaughtExceptionHandler(new ThreadException(exList));  原理:给每个线程添加 UncaughtExceptionHandler,死掉的时候把线程对应的信息加入到一个list里面,然后让主线程每隔一段时间扫描一下list,如果有数据,直接重新建一个线程运行即可  6、如果程序是常驻内存的话,别忘记了在finally中关闭掉 不用的ftp连接  7、做大数据库采集程序必须考虑到的一件事情 磁盘空间已满的处理  java虚拟机对于磁盘空间已满,在英文环境下的 linux aix 机器上 一般报  There is not enough space in the file system  中文环境下 一般报 “磁盘空间已满”  大家可以使用下面的代码进行验证  //linux aix There is not enough space in the file system  // window There is not enough space in the file system  if(e.toString()。contains(”enough space”)||e.toString()。contains(”磁盘空间已满”))  {  log.error(”channel “+channel_name + ” There is not enough space on the disk “);  Runtime.getRuntime()。exit(0);  }

[1][2]

找一个让心里安静和干净的地方,

java大数据处理(千万级别FTP下载)

相关文章:

你感兴趣的文章:

标签云: