Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Registering Driver in getConnection  RSS feed

 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

While doing Code review I came accross following code in getconnection method



I know its very bad programming,but I need comments from experts
so kindly tell me some disastars of using above code in LIVE env.

Cheers
Prafu
[ September 20, 2004: Message edited by: Ilja Preuss ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a) The catch block immediately throws - so it's needless.
Remove it.
After that, the declaration of 'conn' might be put to the initialisation.
But it's returned immediately, so we remove it at all, and return the the result of the DM.gC-call.

b) The general Exception Exception can occur everywhere (OutOfMemoryException) so you don't declare it at all.
Remove it.
c) imports where not invented for the trashcan. Use them, to make code more readable. As long as no naming-conflicts occur, it's perfectly ok to import with * (while some developers don't like it).
d) newInstance () is only noise.
Remove it.


Now we have something readable and may start thinking.
There is no parameter passed (url, database, ...) - so I guess there is only one database-url, one user and password.
If I guess right, and the code is used to get multiple connections, the 'vConstants could be stored static, to evaluate them only once.
But it depends on the usage of the class:


[ September 20, 2004: Message edited by: Stefan Wagner ]
[ September 20, 2004: Message edited by: Stefan Wagner ]
 
Daniel Mayer
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stefan Wagner:
(OutOfMemoryException)


That's actually ab Error, not an Exception.

Full agreement in all other points, though.

Performance problems will only arise if the method is *very* heavily used, though...
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan and Daniel Thanx a bunch for your replies,

Stefan that was gr8 code reiview ..
I would appreciate if you can tell me the performance issues,
Daniel This method is called heavily from an BANKING application

Cheers
Praful
 
Daniel Mayer
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Praful Thakare:
Daniel This method is called heavily from an BANKING application


Please define "heavily" - how often in a second?
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel,
This application is yet to go live,but as per my knowledge it will be called
atleas once per second in working hours

-P
 
Daniel Mayer
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Praful Thakare:
This application is yet to go live,but as per my knowledge it will be called
atleas once per second in working hours


OK - until it becomes likely that it will be called several hundred times a second, I wouldn't waste another thought on it...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!