pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

Apache Commons FTPClient 掛起

Apache Commons FTPClient Hanging(Apache Commons FTPClient 掛起)
本文介紹了Apache Commons FTPClient 掛起的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我們正在使用以下 Apache Commons Net FTP 代碼連接到 FTP 服務(wù)器,輪詢一些目錄中的文件,如果找到文件,則將它們檢索到本地計(jì)算機(jī):

We are using the following Apache Commons Net FTP code to connect to an FTP server, poll some directories for files, and if files are found, to retrieve them to the local machine:

try {
logger.trace("Attempting to connect to server...");

// Connect to server
FTPClient ftpClient = new FTPClient();
ftpClient.setConnectTimeout(20000);
ftpClient.connect("my-server-host-name");
ftpClient.login("myUser", "myPswd");
ftpClient.changeWorkingDirectory("/loadables/");

// Check for failed connection
if(!FTPReply.isPositiveCompletion(ftpClient.getReplyCode()))
{
    ftpClient.disconnect();
    throw new FTPConnectionClosedException("Unable to connect to FTP server.");
}

// Log success msg
logger.trace("...connection was successful.");

// Change to the loadables/ directory where we poll for files
ftpClient.changeWorkingDirectory("/loadables/");    

// Indicate we're about to poll
logger.trace("About to check loadables/ for files...");

// Poll for files.
FTPFile[] filesList = oFTP.listFiles();
for(FTPFile tmpFile : filesList)
{
    if(tmpFile.isDirectory())
        continue;

    FileOutputStream fileOut = new FileOutputStream(new File("tmp"));
    ftpClient.retrieveFile(tmpFile.getName(), fileOut);
    // ... Doing a bunch of things with output stream
    // to copy the contents of the file down to the local
    // machine. Ommitted for brevity but I assure you this
    // works (except when the WAR decides to hang).
    //
    // This was used because FTPClient doesn't appear to GET
    // whole copies of the files, only FTPFiles which seem like
    // file metadata...
}

// Indicate file fetch completed.
logger.trace("File fetch completed.");

// Disconnect and finish.
if(ftpClient.isConnected())
    ftpClient.disconnect();

logger.trace("Poll completed.");
} catch(Throwable t) {
    logger.trace("Error: " + t.getMessage());
}

我們計(jì)劃每分鐘每分鐘運(yùn)行一次.當(dāng)部署到 Tomcat (7.0.19) 時(shí),此代碼加載得非常好,并且可以順利開始工作.但每次,在某個(gè)時(shí)候,它似乎只是掛起.我的意思是:

We have this scheduled to run every minute, on the minute. When deployed to Tomcat (7.0.19) this code loads up perfectly fine and begins working without a hitch. Every time though, at some point or another, it seems to just hang. By that I mean:

  • 不存在堆轉(zhuǎn)儲(chǔ)
  • Tomcat 仍在運(yùn)行(我可以看到它的 pid 并且可以登錄到 Web 管理器應(yīng)用程序)
  • 在管理器應(yīng)用中,我可以看到我的 WAR 仍在運(yùn)行/啟動(dòng)
  • catalina.out 和我的特定于應(yīng)用程序的日志顯示沒有任何異常被拋出的跡象
  • No heap dumps exist
  • Tomcat is still running (I can see its pid and can log into the web manager app)
  • Inside the manager app, I can see my WAR is still running/started
  • catalina.out and my application-specific log show no signs of any exceptions being thrown

所以 JVM 仍在運(yùn)行.Tomcat 仍在運(yùn)行,我部署的 WAR 仍在運(yùn)行,但它只是掛起.有時(shí)運(yùn)行 2 小時(shí)然后掛起;其他時(shí)候它會(huì)運(yùn)行幾天然后掛起.但是當(dāng)它掛起時(shí),它會(huì)在讀取 About to check loadables/for files... 的行(我確實(shí)在日志中看到)和讀取 File fetch 的行之間這樣做完成.(我沒看到).

So the JVM is still running. Tomcat is still running, and my deployed WAR is still running, but its just hanging. Sometimes it runs for 2 hours and then hangs; other times it runs for days and then hangs. But when it does hang, it does so between the line that reads About to check loadables/ for files... (which I do see in the logs) and the line that reads File fetch completed. (which I don't see).

這告訴我在文件的實(shí)際輪詢/獲取過程中發(fā)生了掛起,這使我指向了與 this question 我能夠找到與 FTPClient 死鎖有關(guān)的問題.這讓我想知道這些問題是否相同(如果是,我會(huì)很樂意刪除這個(gè)問題!).但是我不認(rèn)為相信它們是相同的(我在我的日志中沒有看到相同的異常).

This tells me the hang occurs during the actual polling/fetching of the files, which kind of points me in the same direction as this question that I was able to find which concerns itself with FTPClient deadlocking. This has me wondering if these are the same issues (if they are, I'll happily delete this question!). However I don't think believe they're the same (I don't see the same exceptions in my logs).

一位同事提到它可能是被動(dòng)"與主動(dòng)"的 FTP 事情.不知道有什么區(qū)別,我對(duì) FTPClient 字段 ACTIVE_REMOTE_DATA_CONNECTION_MODEPASSIVE_REMOTE_DATA_CONNECTION_MODE 等感到有些困惑,并且不知道 SO 認(rèn)為這是一個(gè)潛在問題.

A co-worker mentioned it might be a "Passive" vs. "Active" FTP thing. Not really knowing the difference, I am a little confused by the FTPClient fields ACTIVE_REMOTE_DATA_CONNECTION_MODE, PASSIVE_REMOTE_DATA_CONNECTION_MODE, etc. and didn't know what SO thought about that as being a potential issue.

由于我在這里將 Throwable 作為最后的手段,因此如果出現(xiàn)問題,我本來希望在日志中看到 something.因此,我覺得這是一個(gè)明確的掛起問題.

Since I'm catching Throwables as a last resort here, I would have expected to see something in the logs if something is going wrong. Ergo, I feel like this is a definite hang issue.

有什么想法嗎?不幸的是,我對(duì)這里的 FTP 內(nèi)部知識(shí)知之甚少,無法做出明確的診斷.這可能是服務(wù)器端的東西嗎?跟FTP服務(wù)器有關(guān)嗎?

Any ideas? Unfortunately I don't know enough about FTP internals here to make a firm diagnosis. Could this be something server-side? Related to the FTP server?

推薦答案

這可能是很多事情,但你朋友的建議是值得的.

This could be a number of things, but your friend's suggestion would be worthwhile.

試試 ftpClient.enterLocalPassiveMode(); 看看是否有幫助.

Try ftpClient.enterLocalPassiveMode(); to see if it helps.

我還建議將斷開連接放在 finally 塊中,這樣它就不會(huì)留下連接.

I would also suggest to put the disconnect in the finally block so that it never leaves a connection out there.

這篇關(guān)于Apache Commons FTPClient 掛起的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 特材真空腔体_哈氏合金/镍基合金/纯镍腔体-无锡国德机械制造有限公司 | 上海单片机培训|重庆曙海培训分支机构—CortexM3+uC/OS培训班,北京linux培训,Windows驱动开发培训|上海IC版图设计,西安linux培训,北京汽车电子EMC培训,ARM培训,MTK培训,Android培训 | 深圳快餐店设计-餐饮设计公司-餐饮空间品牌全案设计-深圳市勤蜂装饰工程 | 网站制作优化_网站SEO推广解决方案-无锡首宸信息科技公司 | 北京租车牌|京牌指标租赁|小客车指标出租 | 贵州成人高考网_贵州成考网 | 立式_复合式_壁挂式智能化电伴热洗眼器-上海达傲洗眼器生产厂家 理化生实验室设备,吊装实验室设备,顶装实验室设备,实验室成套设备厂家,校园功能室设备,智慧书法教室方案 - 东莞市惠森教学设备有限公司 | 防水套管厂家_刚性防水套管_柔性防水套管_不锈钢防水套管-郑州中泰管道 | 专业生产动态配料系统_饲料配料系统_化肥配料系统等配料系统-郑州鑫晟重工机械有限公司 | 废水处理-废气处理-工业废水处理-工业废气处理工程-深圳丰绿环保废气处理公司 | 上海瑶恒实业有限公司|消防泵泵|离心泵|官网 | 天津蒸汽/热水锅炉-电锅炉安装维修直销厂家-天津鑫淼暖通设备有限公司 | 进口便携式天平,外校_十万分之一分析天平,奥豪斯工业台秤,V2000防水秤-重庆珂偌德科技有限公司(www.crdkj.com) | 无菌水质袋-NASCO食品无菌袋-Whirl-Pak无菌采样袋-深圳市慧普德贸易有限公司 | 车充外壳,车载充电器外壳,车载点烟器外壳,点烟器连接头,旅行充充电器外壳,手机充电器外壳,深圳市华科达塑胶五金有限公司 | 主题班会网 - 安全教育主题班会,各类主题班会PPT模板 | 悬浮拼装地板_篮球场木地板翻新_运动木地板价格-上海越禾运动地板厂家 | 高低温万能试验机_拉力试验机_拉伸试验机-馥勒仪器科技(上海)有限公司 | 南溪在线-南溪招聘找工作、找房子、找对象,南溪综合生活信息门户! | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 冰晶石|碱性嫩黄闪蒸干燥机-有机垃圾烘干设备-草酸钙盘式干燥机-常州市宝康干燥 | 氮化镓芯片-碳化硅二极管 - 华燊泰半导体| 【孔氏陶粒】建筑回填陶粒-南京/合肥/武汉/郑州/重庆/成都/杭州陶粒厂家 | 莱州网络公司|莱州网站建设|莱州网站优化|莱州阿里巴巴-莱州唯佳网络科技有限公司 | 十二星座查询(性格特点分析、星座运势解读) - 玄米星座网 | 百方网-百方电气网,电工电气行业专业的B2B电子商务平台 | 防水套管-柔性防水套管-刚性防水套管-上海执品管件有限公司 | 艾乐贝拉细胞研究中心 | 国家组织工程种子细胞库华南分库 | 贵阳用友软件,贵州财务软件,贵阳ERP软件_贵州优智信息技术有限公司 | 成都治疗尖锐湿疣比较好的医院-成都治疗尖锐湿疣那家医院好-成都西南皮肤病医院 | 医院专用门厂家报价-医用病房门尺寸大全-抗菌木门品牌推荐 | 钢木实验台-全钢实验台-化验室通风柜-实验室装修厂家-杭州博扬实验设备 | 浙江红酒库-冰雕库-气调库-茶叶库安装-医药疫苗冷库-食品物流恒温恒湿车间-杭州领顺实业有限公司 | 气胀轴|气涨轴|安全夹头|安全卡盘|伺服纠偏系统厂家-天机传动 | 品牌策划-品牌设计-济南之式传媒广告有限公司官网-提供品牌整合丨影视创意丨公关活动丨数字营销丨自媒体运营丨数字营销 | 上海小程序开发-小程序制作-上海小程序定制开发公司-微信商城小程序-上海咏熠 | 宿舍管理系统_智慧园区系统_房屋/房产管理系统_公寓管理系统 | 酒水灌装机-白酒灌装机-酒精果酒酱油醋灌装设备_青州惠联灌装机械 | 聚合氯化铝厂家-聚合氯化铝铁价格-河南洁康环保科技 | 天津仓库出租网-天津电商仓库-天津云仓一件代发-【博程云仓】 | 广州监控安装公司_远程监控_安防弱电工程_无线wifi覆盖_泉威安防科技 |