方法介绍:

    * There are a few FTPClient methods that do not complete the
* entire sequence of FTP commands to complete a transaction. These
* commands require some action by the programmer after the reception
* of a positive intermediate command. After the programmer's code
* completes its actions, it must call this method to receive
* the completion reply from the server and verify the success of the
* entire transaction.
public boolean completePendingCommad() throws IOException;
{
return FTPReply.isPositiveCompletion(getReply());
}

方法介绍中未说明,在何种情况下应该使用该方法。但是跟踪代码可以发现
这是一个同步阻塞方法,如果调用错误,会导致程序卡住假死在这里。

卡住代码
String line = _controlInput_.readLine();

何时调用?

其实ftp功能,总结来说,只有上传和下载。只有在获取返回流时,才需要调用completePendingCommad方法,因为返回流不是立刻处理的。所以需用手动调用结束方法。

public boolean storeFile(String remote, InputStream local)
public OutputStream storeFileStream(String remote) public boolean retrieveFile(String remote, OutputStream local)
public InputStream retrieveFileStream(String remote)

我们看到上面4个人方法,其中两个有流返回,另外两个无返回。当调用有返回流方法时,需要手动调用completePendingCommad方法,即第二个和第四个是需要调用completePendingCommad方法,其他两个方法如果调用了,则会产生卡死超时现象。

注意事项

不可多加或者漏加,否则会导致程序卡死

参考链接

commons-net FTPClient API存取设计

Commons-net FTPClient completePendingCommand()经常使程序死掉的原因分析以及解决方式

作者:北海北_6dc3
链接:https://www.jianshu.com/p/a90cc2aeefca
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

最新文章

  1. BZOJ 1968: [Ahoi2005]COMMON 约数研究
  2. vs2012中添加lib,.h文件方法(原)
  3. js数组转置
  4. 【Moqui业务逻辑翻译系列】Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和机会
  5. 深入了解A*
  6. 160907、CSS 预处理器-Less
  7. 直接拿来用 九个超实用的PHP代码片段(二)
  8. BZOJ 1934: [Shoi2007]Vote 善意的投票 最小割
  9. android自定义控件---添加表情
  10. 白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连续7-电话问卷调查
  11. mysql插入数据报错1366
  12. [React] 06 - Route: koa makes your life easier
  13. 数据结构(C语言版)-第4章 串、数组和广义表
  14. 在Java中谈尾递归--尾递归和垃圾回收的比较
  15. [javaSE] 多线程(售票例子)
  16. 关于“CheckBox”通过表单提交的问题
  17. maven镜像制作
  18. BZOJ1233 [Usaco2009Open]干草堆tower 【单调队列优化dp】
  19. js 禁止用户使用Ctrl+鼠标滚轮缩放网页
  20. [RK3288][Android6.0] 调试笔记 --- 通用GPIO驱动控制LED【转】

热门文章

  1. 【Gamma】 Phylab 展示博客
  2. expect脚本自动获取root权限
  3. Maven 教程(7)— Maven使用的最佳实践
  4. [IOI 1994]数字三角形
  5. 修改ssh服务器默认端口号
  6. python 基础 ---- 面向对象
  7. Effective.Java第78-90条(同步相关)
  8. Scala2.12 从入门到精通实战高端视频课程(含网盘下载地址)
  9. 彻底搞懂Javascript的this
  10. K8S学习笔记之Kubernetes 配置管理 ConfigMap