我们爱分享---Too many open files 问题的解决办法

yungmode yungmode 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
linux 上tomcat 服务器抛出socket异常“文件打开太多”的问题
java.net.SocketException: Too many open files
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
at java.net.ServerSocket.implAccept(ServerSocket.java:450)
at java.net.ServerSocket.accept(ServerSocket.java:421)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60)
at org.apache.tomcat.util.net.PoolTcpEndpoint.acceptSocket(PoolTcpEndpoint.java:407)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:70)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
原本以为是tomcat的配置或是应用本身的问题,"谷歌"一把后才发现,该问题的根本原因是由于系统文件资源的限制导致的。
具体的解决方式可以参考一下:
1。ulimit -a 查看系统目前资源限制的设定。
[root@test security]# umlimit -a
-bash: umlimit: command not found
[root@test security]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 7168
virtual memory (kbytes, -v) unlimited
[root@test security]#
通过以上命令,我们可以看到open files 的最大数为1024
那么我们可以通过一下命令修改该参数的最大值
2. ulimit -n 4096
[root@test security]# ulimit -n 4096
[root@test security]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 4096
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 7168
virtual memory (kbytes, -v) unlimited
这样我们就修改了系统在同一时间打开文件资源的最大数,基本解决以上问题。
以上部分是查找网络上的解决方法。设置了之后段时间内有作用。
后来仔细想来,问题还是要从根本上解决,于是把以前的代码由认真地看了一遍。终于找到了,罪魁祸首。在读取文件时,有一些使用的BufferedReader 没有关闭。导致文件一直处于打开状态。造成资源的严重浪费。修改之后的简单代码如下:
public void test(){
BufferedReader reader =null;
try{
reader = 读取文件;
String line = "";
while( ( ine=reader.readLine())!=null){
其他操作
}

} catch (IOException e){
System.out.println(e);
} finally{
if(reader !=null){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

}


来源于互联网
...全文

相关推荐

weblogic管理手册

weblogic管理手册..............

laoson962006

Sublime Text Build 3124 x64 Setup.exe

因为网络原因下载极慢。windows64版本在此分享~ 今天发布的3124, Release Date: 22 September 2016 See also the Blog Post Settings now open in a new window, with the default and user settings side-by-side Hovering over a symbol will show a popup indicating where it's defined. This is controlled with the show_definitions setting. Build errors are now shown inline at the location where they occurred. This is controlled with the show_errors_inline setting. Added a menu item and command palette entry to install Package Control Various syntax highlighting improvements Significant improvements to the Scala syntax definition, with thanks to djspiewak and gwenzek Significant improvements to the LaTeX syntax definition, with thanks to randy3k Improved Goto Definition performance when a large number of files are open Minor improvements to file load times Linux and OSX: Improved memory usage Fixed Replace not working as expected in conjunction with regex look behinds Fixed build systems being unable to use "file_patterns" with the exec command Corrected tab overlap on HiDPI Windows and Linux configurations OSX: Fixed a graphical glitch when switching tabs OSX: Fixed crash when entering a surrogate pair via hex input Linux: Improved rendering performance for some systems File encoding of open files is now stored in the session Build Systems may define a cancel command using the "cancel" key Syntax: Added clear_scopes directive, to give more control over the generated scopes Color Schemes: Added popupCss key, for defining default popup style sheets Color Schemes: Added phantomCss key, for defining default phantom style sheets minihtml: HiDPI support was added for Windows and Linux minihtml: Windows style line endings and single quoted attributes are now supported minihtml: Child selectors may now be used in style sheets minihtml: The inherit CSS value has been implemented minihtml: font-family stacks may now be used minihtml: Support for the line-height CSS property was added minihtml: Elements may now be relatively positioned minihtml: Inline elements support padding and background-color set minihtml: CSS variables and the var() function are now supported minihtml: Added the CSS color functions color() (partial), rgb(), rgba(), hsl() and hsla() minihtml: Fixed a stack overflow on Windows with too many unclosed tags API: Added Phantom and PhantomSet API: Added ViewEventListener API: Added View.is_primary() API: Added EventListener.on_hover(view, point, hover_zone) API: Added functions to get and set visibility of the minimap, status bar, tabs and menu API: Modifications to a selection are now constrained to the valid range API: Updated Python 3.3 to commit 8e3b9bf917a7, and SQLite to 3.14.1 Packages: Loading packages will no longer abort if a .sublime-package is corrupt Packages: Fixed an edge case when loading third party packages from unicode paths on Windows

苏轶然

BEA dev2dev WebLogic管理精华

BEA dev2dev WebLogic管理精华

zhiwei152

【荐】mysql服务性能优化—my.cnf_my.ini配置说明详解(16G内存)

此配置是老男孩生产线上使用的配置,这配置已经优化的不错了,如果你的mysql没有什么特殊情况的话,可以直接使用该配置参数 对各参数添加了中文说明 ======= back_log = 600 #在MYSQL暂时停止响应新请求之前,短时间内的多少个请求可以被存在堆栈中。如果系统在短时间内有很多连接,则需要增大该参数的值,该参数值指定到来的TCP/IP连接的监听队列的大小。默认值50。 max_connections = 3000 #MySQL允许最大的进程连接数,如果经常出现Too Many Connections的错误提示,则需要增大此值。 ……

freesit

PDF发票内容提取排版并结构化导出xlsx/cvs嵌入式ptyhon

【本地发票提取工具】 核心优势:不依赖传统粗糙 OCR,基于文字排版结构进行精准提取。仅“税网”下载及税网邮件发送的原版 PDF 发票(开票软件发送的不太支持)能实现开票明细级的秒级本地提取,告别只能提抬头、总额的尴尬。 可免费试用 3 天! 【用前须知】 去微软官网下载VC_redist.x64.exe运行修复运行库(必要的前置操作),之后再解压本工具rar,运行本exe即可。 VC_redist.x64.exe官网永久下载地址 https://learn.microsoft.com/zh-cn/cpp/windows/latest-supported-vc-redist 【安全须知】 个人开发暂未做代码签名,杀软可能会有误报拦截。遇到拦截请在杀软中添加信任/白名单即可。 VirusTotal扫描结果 2/61,主流杀软均通过,个别引擎因无签名误报。官网 virustotal.com 点击页面中间显眼的 “Choose file”(选择文件)按钮上传扫描。

信人远邮168
评论 2
收藏 已收藏
分享
返回顶部
yungmode
Java EE 67,535 成员 225,843 内容