This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
adi sembiring
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
adi sembiring
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic