aspose file tools*
The moose likes Java in General and the fly likes The application requester cannot establish the connection. (Too many open files) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "The application requester cannot establish the connection. (Too many open files)" Watch "The application requester cannot establish the connection. (Too many open files)" New topic
Author

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

adi sembiring
Greenhorn

Joined: Nov 13, 2009
Posts: 9
I develop application run in Websphere work manager. work manager is used to run thread in the webpshere applications erver.

Every 5 minutes my thread try to get some data from MySQL database from the different host from the application server machine.

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. this is the exception: com.mysql.jdbc.CommunicationsException:



But, over time my program get exception as follows:



and this exception make my application server crash:



I need suggestion how to fix this problem and prevent my application being crash?



WorkEnvironment:

Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

That could be down to the unix system running out of file descriptors, because of too many open sockets.
Make sure that you always close an opened connection when you're done using it.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

adi sembiring wrote:I need suggestion how to fix this problem and prevent my application being crash?

Always close resources that aren't needed anymore. Not just SQL connections but (Prepared)Statements, ResultSets, InputStreams, OutputStreams, Readers, Writers, etc. You usually do this in a finally block. You can use nested try-finally blocks if you have more than one resource. For instance:
It may look confusing, but this way ensures that all resources will always be closed, even if exceptions occur. The nesting prevents a) having to check against null, and b) because close() can also throw an exception, that failing to close one resource will lead to other resources not being closed.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
adi sembiring
Greenhorn

Joined: Nov 13, 2009
Posts: 9
Rob Prime wrote:
adi sembiring wrote:I need suggestion how to fix this problem and prevent my application being crash?

Always close resources that aren't needed anymore. Not just SQL connections but (Prepared)Statements, ResultSets, InputStreams, OutputStreams, Readers, Writers, etc. You usually do this in a finally block. You can use nested try-finally blocks if you have more than one resource. For instance:
It may look confusing, but this way ensures that all resources will always be closed, even if exceptions occur. The nesting prevents a) having to check against null, and b) because close() can also throw an exception, that failing to close one resource will lead to other resources not being closed.


Honestly I use Hibernate to make data access to the database.

while the anotationconfiguration build session factory, it will make connection and add the connection pooling. should I close the session factory even though I get exception when the buildSessionFactory can not connect to the database host ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

You of course only close successfully opened connections. The pooling mechanism will ensure that the connection will not be really closed but instead returned to the pool.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The application requester cannot establish the connection. (Too many open files)