Should a database connection stay open all the time or only be opened when needed?

前端 未结 6 1386
天命终不由人
天命终不由人 2020-11-28 11:39

I have a bukkit plugin (minecraft) that requires a connection to the database.

Should a database connection stay open all the time, or be opened and closed when nee

6条回答
  •  無奈伤痛
    2020-11-28 12:16

    Depends on what are your needs.

    Creating a connection takes some time, so if you need to access database frequently it's better to keep the connection open. Also it's better to create a pool, so that many users can access database simultaneously(if it's needed).

    If you need to use this connection only few times you may not keep it open, but you will have delay when you would like to access database. So i suggest you to make a timer that will keep connection open for some time(connection timeout).

提交回复
热议问题