简体   繁体   English

应用程序请求者无法建立连接。 (打开的文件太多)

[英]The application requester cannot establish the connection. (Too many open files)

I develop application run in Websphere work manager. 我开发在Websphere工作管理器中运行的应用程序。 work manager is used to run thread in the webpshere applications erver. 工作管理器用于在webpshere应用程序erver中运行线程。

Every 5 minutes my thread try to get some data from MySQL database from the different host from the application server machine. 我的线程每隔5分钟尝试从与应用程序服务器计算机不同的主机的MySQL数据库中获取一些数据。

When the Host of MySql database turned off, The work manager always try to connect to MySQL database and I know my program will always get exception connection failure. 当MySql数据库的主机关闭时,工作管理器将始终尝试连接到MySQL数据库,并且我知道我的程序将始终出现异常连接失败。 this is the exception: com.mysql.jdbc.CommunicationsException: 这是例外:com.mysql.jdbc.CommunicationsException:

Communications link failure due to underlying exception

But, over time my program get exception as follows: 但是,随着时间的流逝,我的程序会出现如下异常:

java.sql.SQLException: The application requester cannot establish the connection. (Too many open files)

and this exception make my application server crash: 并且此异常使我的应用程序服务器崩溃:

[8/2/10 9:07:21:613 ICT] 00000d54 prefs         W   Could not lock User prefs. Unix error code 24.
[8/2/10 9:07:21:613 ICT] 00000d54 prefs         W   Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.

I need suggestion how to fix this problem and prevent my application being crash ???? 我需要建议如何解决此问题并防止我的应用程序崩溃?

WorkEnvironment: 工作环境:

Operation System AIX
Application Server Webpshere 7.0

It sounds like you have a file descriptor leak. 听起来您有文件描述符泄漏。

Some part of your code (or some other code running on the machine) is creating more and more file handles, including sockets, and is not closing them. 您代码的某些部分(或在计算机上运行的其他代码)正在创建越来越多的文件句柄(包括套接字),并且没有关闭它们。 Based on your description, it sounds like it's your code that's doing this. 根据您的描述,这听起来像是您的代码正在执行此操作。

I suspect that when you create the socket, you're not closing it cleanly when an exception is thrown. 我怀疑在创建套接字时,抛出异常时并不能完全关闭套接字。 If you don't do this, then the socket will stay open and over time you'll run out of files. 如果不这样做,套接字将保持打开状态,随着时间的流逝,文件将用完。 Any resource that needs to be closed after use should always be closed in a try-finally block, to ensure that the resource will be closed regardless of the path through the method. 使用后需要关闭的任何资源都应始终try-finally块中关闭,以确保无论通过该方法的路径如何,都将关闭该资源。

If you don't think you're leaking files, use the lsof utility on the host to see what file handles are being held open by your process, and check that you do legitimately need all of them. 如果您不认为自己在泄漏文件,请使用主机上的lsof实用工具查看进程中哪些文件句柄处于打开状态,并检查您是否确实需要所有这些文件句柄。 I find it unlikely that you have a legitimate reason to exceed the default FD limit of the system. 我发现您不太可能出于正当理由超过系统的默认FD限制。

Generally speaking, when you connect to a database, you have some sort of open call to open the connection, then you do some work with the connection, and then you close the connection. 一般来说,当您连接到数据库时,您会有某种打开调用来打开连接,然后对连接进行一些处理,然后关闭连接。 If you've forgotten to close the connection, you can run out of resources quickly and get an error like the one you're seeing. 如果您忘记关闭连接,则可能会很快耗尽资源,并收到与您看到的错误类似的错误消息。 However, even if you did remember to close the connection, you might hit an exception while doing the work that would cause flow of execution to bypass the close call. 但是,即使您确实记得关闭连接,在执行工作时也可能会遇到异常,这将导致执行流程绕过close调用。 For that reason, you always want the work to be wrapped in a try block, and the close call to be in a finally block. 因此,您始终希望将工作包装在try块中,并将close调用包装在finally块中。 Could that be your problem? 那可能是你的问题吗?

I had faced similar problem. 我曾经遇到过类似的问题。 I fixed it by increasing ulimit of my user on OS. 我通过增加用户在OS上的ulimit来解决此问题。 This occurs because there's a limit to the number of open files in most of the operating systems. 发生这种情况是因为在大多数操作系统中,打开文件的数量受到限制。

On linux box you can do it by following command. 在linux上,您可以通过以下命令进行操作。 Here I have set it to unlimited. 在这里,我将其设置为无限制。

ulimit -u unlimited

You can also check current limits by running : 您还可以通过运行以下命令检查电流限制:

>ulimit -a       
      core file size (blocks)   1000000
      data seg size (kbytes)    unlimited
      file size (blocks)            unlimited
      max memory size (kbytes)  unlimited
      stack size (kbytes)           8192
      cpu time (seconds)            unlimited
      max user processes            unlimited  
      pipe size (512 bytes)         8
      open files                    1024
      virtual memory (kbytes)   2105343

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM