Java中的SQLite连接池 - 锁定数据库 [英] SQLite Connection Pool in Java - Locked Database

查看:92
本文介绍了Java中的SQLite连接池 - 锁定数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在多线程环境中阅读了几个关于SQLite的相关主题,但我找不到明确的声明,所以请原谅我再次提出这个主题。

I have already read several related threads about SQLite in multi-threaded environments but I could not find a clear statement, so forgive me that I bring up this topic yet another time.

我需要从多个线程访问应用程序的数据库来执行更新语句。数据库本身可以是SQLite或MySQL,具体取决于用户的选择。对于MySQL处理程序,我使用tomcat-jdbc库实现了一个连接池。现在我正在寻找SQLite处理程序的最佳方法,因为正常的连接池不应该工作,因为SQLite一次只支持一个写入连接来锁定整个数据库。

I need to access the application's database from multiple threads to execute update statements. The database itself can be SQLite or MySQL, depending on the users choice. For the MySQL handler, I have implemented a connection pool using the tomcat-jdbc library. Now I am searching the best way for the SQLite handler, since normal connection-pooling should not work as SQLite only supports one writing connection at a time that locks the whole database.

我是否应该继续使用相同的连接一个接一个地进行所有线程(通过同步连接?),还是应该使用已经存在的仅存在连接的tomcat库创建连接池?一个连接的连接池可能超大吗?

Should I just go ahead and make all Threads using the same connection one after another (by synchronizing the connection?) or should I create a connection pool using the already present tomcat library that holds just connection? Might a connection pool with one connection be oversized?

推荐答案

由于它是单文件嵌入式数据库,因此池化几乎没有用处。

Since it is single file embedded database, pooling will hardly be beneficial.

https://web.archive.org/web/20130410192252/http://sqlite.phxsoftware.com/forums/p/682/3034.aspx

由于原始网站已关闭,我将提供摘要:

Since the original site is down, I will provide the summary:


我有我的使用池化的
连接实现池化和1000个命令,并且池化速度更接近
单连接速度。

I have my pooling implemented and 1000 commands using a pooled connection and the pooled speed was much closer to the single-connection speed.



Many non-pooled connections : 2875.0 ms
Many pooled connections     :   93.8 ms
Pooled with reset           :  546.9 ms
One Connection              :   46.9 ms

因此,共识是汇集不是非常有益。

So the consensus is that pooling is not very beneficial.

http://www.sqlite.org/faq.html#q5

http://www.sqlite.org/threadsafe.html

这篇关于Java中的SQLite连接池 - 锁定数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆