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

2014-11-24 11:24:42 · 作者: · 浏览: 14
;
}
}
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
中文环境下 一般报 "磁盘空间已满"
大家可以使用下面的代码进行验证 www.2cto.com
//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);
}