久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Apache Commons FTPClient 掛起

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

問(wèn)題描述

我們正在使用以下 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)用程序的日志顯示沒(méi)有任何異常被拋出的跡象
  • 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 的行之間這樣做完成.(我沒(méi)看到).

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

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è)潛在問(wèn)題.

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)問(wèn)題,我本來(lái)希望在日志中看到 something.因此,我覺(jué)得這是一個(gè)明確的掛起問(wèn)題.

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ú)法做出明確的診斷.這可能是服務(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)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(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ù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 超碰在线影院 | 成人精品久久久 | 亚洲永久免费 | 超碰人人在线 | 久久人体视频 | 免费精品 | www.欧美| www.久草.com | 亚洲成人观看 | 午夜成人免费电影 | 一级午夜aaa免费看三区 | 久久久久综合 | 久久久精品久久久 | 日韩a v在线免费观看 | 午夜影院视频在线观看 | 国产乱码精品一区二区三区忘忧草 | 91精品国产91久久久久久吃药 | 日韩三级在线观看 | 干干干日日日 | 久久国产高清 | 亚洲一页| 国产一区2区 | av网址在线 | 国产精品久久久久久久免费大片 | 色婷婷av一区二区三区软件 | 久草精品视频 | 国产一区二区在线播放视频 | 欧美性吧| 免费人成激情视频在线观看冫 | 亚洲国产成人精品女人久久久 | 亚洲精选一区二区 | 亚洲精品国产成人 | 欧美激情在线一区二区三区 | av一级久久 | 午夜丁香视频在线观看 | 97av在线| 久久久久久久一级 | 国产精品美女www爽爽爽 | aaa精品 | 天天看天天爽 | 麻豆91精品91久久久 |