Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection timeout issues

 
Sasikanth Malladi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

I have an application that connects to a DB via JDBC.
In the init() method of my app, I'm initializing the connection to the DB.
When the client makes a request, the connection will be used to run a query and get the results.
My problem is this: mine is a long running server process. It could sometimes be days or hours between requests and the DB connection is closed.
How do I keep this connection alive indefinitely?
What are the typical approaches in this case? Would connection pooling be a good idea?
Thanks for any pointers,
Sashi
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before doing anything tricky, I'd ask how important it is.

What bad things happen if you connect, query, disconnect every time you access the database? If you're about to say it's slow, have you measured how slow?

What good things happen if you connect every time? If the database stops and restarts, no problem. If a momentary network outage kills one attempt, the next one will still work fine.
 
Sasikanth Malladi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good answer, Stan.

I've been brainwashed into thinking about "expensive" connections and I automatically avoided that route without experimenting.

It turns out that the time times is less than 100 ms for a connection.

For my application, that is perhaps within allowable limits.

Regards,
Sashi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic