This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How Stealed connection will exists?  RSS feed

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All

As we heard stealed connection's exists because of improper closing of connection in the application. so why cant we use static variables for Connection,ResultSet,Statement and close them using finalize method in my appllication instead of closing the connection in all the methods is it eliminates the stealed connection
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the previous post

Its stale Connections
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36463
462
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santosh,
A stale connection is caused by a timeout with the database. Making a connection a static variable increases the chance of a stale connection. Since the static variable lives for the life of the program, odds are that connection will experience a timeout sooner or later.
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Making a connection a static variable increases the chance of a stale connection. Since the static variable lives for the life of the program


Is it possible to eliminate the stale connections by making declaring the connection object inside the method (Not declaring as static out side)
 
Sandeep Sanaboyina
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not possible to eliminate stale connections. As Jeanne said, it is caused by a timeout with the DB- and we cannot control that timeout as it is configured at the DB level.

It's best to handle stale connections effectively in your code and get a new connection in case you get one.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!