0

I'm currently developing plugins for bukkit and a lot of them need a database connection. Now I'm thinking about if could be better to have just one plugin that handles the connection for all plugins.

The question behind that is if it is good or not to keep a connection up even if there are no queries for some minutes (that may happen). Otherwise I would need to establish a new connection for each query?

K. D.
  • 4,041
  • 9
  • 48
  • 72

2 Answers2

2

It is a good idea to have one class/plugin for handling database, but the connection state should not be open all the time,make sure the connection is opened only for the time taken by the query.

Ratna
  • 2,289
  • 3
  • 26
  • 50
  • But I thought that I can save time and ressources if I prevent to open the connections again and again. For example if one plugin should execute one statement every 5 minutes, should I reopen the connection again everytime? If so, why? – K. D. Apr 16 '13 at 11:56
  • yes you should reopen the connection every time, actually connection pooling will handle it and will take less resources than you are thinking. When your application will grow and no. of concurrent users grow a time will come when there will be no resources left to create a new connection to avoid this always close the connection. when you reopen a connection it is fetched from the pool and is not necessary a new connection is created. – Ratna Apr 16 '13 at 12:12
  • Okay and If I use a connectionpool like boneCP can I make it static to share it? – K. D. Apr 16 '13 at 12:59
0

Many applications use connection pools to have a number of connections readily available to run queries over. It reduces the number of protocol re-negotiations that the database driver has to do. This is especially useful for applications that need fast access times to the underlying data, yet have larger downtimes between requests. E-Commerce applications like webshops are a good example.

0xCAFEBABE
  • 5,576
  • 5
  • 34
  • 59