3

I have a war that requires a permanent jdbc connection.

I've tried this (context.xml)

maxActive="100" 
maxIdle="3" 
maxWait="1000"  
minIdle="1"

But the connection still dies after a while. How can i keep a jdbc connection alive 24/7?

thanks

Jan
  • 13,738
  • 3
  • 30
  • 55
  • keeping IP connections open 24/7 is nigh-impossible, if you want to keep such a connection stable (!) you will need to use database connection pools : https://stackoverflow.com/questions/2835090/how-to-establish-a-connection-pool-in-jdbc – specializt Jan 07 '16 at 16:10
  • which db? and why do you want to that? I mean what useful task you trying to achieve by keeping connection alive? – Sabir Khan Jan 07 '16 at 16:45
  • @SabirKhan it's one of those apps that are used all the time. – Prefijo Sustantivo Jan 12 '16 at 14:29

1 Answers1

1

First of all: you cannot keep it alive forever

At some point something will fail / break. Be it some network interruption, some maintenance of either your software or the database or something else.

So "I want one connection that I can use whenever I need, so it will never close automatically" is not likely to happen for you.

Instead by using a connection pool, you can have: "I want to be able to get a valid and working database connection at any point in time" is quite easy to get in comparison.

Most good connection pools (hikariCP, c3p0, tomcat database pool, ...) support configuration options that guarantee (that is: if the database is up and the network connection works) you can get a valid connection when you need it.

Jan
  • 13,738
  • 3
  • 30
  • 55