Oracle

July 21, 2011

Don’t close that connection

Filed under: Uncategorized — srivenu @ 9:29 am

Consider this scenario.

The cafeteria i eat in, like many others i had seen in India, gives out stainless steel spoons to eat your food. (Ignoring the hygienic factor, I wonder how eco friendly this is, considering the water and soap needed to wash them after each use). At the spoon counter you have a bin into which a cleaning lady periodically dumps a bunch of spoons after each cleaning session. You wait in line at the food counters, get your food, and then come to the spoon counter. Since there is a perennial shortage of spoons, most of the time you wait in line to get a spoon. If your eating time is 20 mins, food counter queue time is 2 mins and spoon counter waiting time in 1 min, you perhaps wouldn’t mind and might take it in your stride. Now what if a person changes his spoon after each mouthful? (You might wonder why someone would think of doing that? That’s stupid ain’t it!) Well we might not do this in real life, but in the programming world, i bet many of us might have seen some strange and similar things indeed!

Let’s say you need to write a java application which periodically wakes up (say every 10 secs or so), checks for any new mail and in case there is any, inserts it into a database. What sort of database connection management do you use for this code? Well, it seems like simple common sense, If it is not multi threaded, you would just open one connection and keep it till the end. But i have seen programs where people have opened and closed the connection for each iteration of the above loop.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: