Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Closing Connection on JSP  RSS feed

 
Satyajit Bhadange
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I encountered this problem at very later stage of my development.

I created Connection object on jsp....and forgot to close those connections...now i ended up with lot of connections open.

now i want to close all this connection..but there are very large number of jsp's in my application.

Now i thought of solution of creating a process or java file..which will give me all alive objects on heap.

and now by using instanceOf operator i can close connection object.

can this be done..if yes then which methods should be used..
is there any class/method which will return enum of object alive on heap...???
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a good example of the troubles that are avoided by following best practices like MVC in which connections would never be made anywhere near a JSP.

I'm afraid that the only solution is to fix each and every JSP so that it closes connections. Trying to traverse the heap looking for open connections, even if it's at all feasible, is just going to make things more complicated and non-standard and should not be followed as a solution.
 
Satyajit Bhadange
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to traverse heap and look for specifc object...

Could it be done...if yes HOW..??

does sun provide such methods or i'l have to write it..

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
 
Gokul Nanthakumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the only solution you have now is to close the connection in every page, technically closing connections outside the JSP as the way you wanted may be possible, but definitely it will lead to more complications in your application, as you may close a connection under use.
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should close your connection on every jsp page.
You idea is complicated and will introduce bugs...

You should also try to use some connection pool
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ultimate solution, of course, is to restructure the application properly, keeping all connection management (using a good connection pool or ORM tool) in the model layer of the application as far away from the JSPs as possible.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!