Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing database between Java and CordovaJs - SQLiteConnectionPool unable to grant a connection #875

Open
kozuch opened this issue Jun 5, 2019 · 2 comments

Comments

@kozuch
Copy link

kozuch commented Jun 5, 2019

I need db sharing between my custom Java code (service) and this plugin (CordovaJS) similar as in #309. I have a single global static SQLiteOpenHelper instance which keeps its "static SQLiteDatabase db" variable. However I sometimes get following error when my Java code tries to access db:

W/SQLiteConnectionPool: The connection pool for database XXX has been unable to grant a connection to thread 2 (main) with flags 0x6 for 8.002001 seconds.
Connections: 0 active, 1 idle, 0 available.

I think I handle all my custom Java db transactions properly, using this scheme:

		db.beginTransaction();
		
		try {
			db.insert(datasynchroobjectTable, colId, cv);
			db.setTransactionSuccessful();
		} catch (SQLiteException e) {
			Log.d("MySqlPlugin", "MySqlPlugin.java transaction CATCH");
		} finally {
			db.endTransaction();
		}

In the constructor of my SQLiteOpenHelper class I do "db = this.getWritableDatabase();"

I tried to patch plugin Java code with proper transaction handling (begin, end etc.) but that did not help. The code is here (version 3.2.0):
https://drive.google.com/file/d/13GWVYVRqY9jE5jHV2geL05pbqE1iLe7p

Can you help me please?

@brodycj
Copy link
Contributor

brodycj commented Jun 7, 2019

Thanks @kozuch, labeled as an enhancement.

This is desired as part of a possible redesign (#548) with API improvements (#862).

Priority is given to paid customers. In case of commercial interest please contact sales@xpbrew.consulting.

@kozuch
Copy link
Author

kozuch commented Jul 23, 2019

Thanks for reply. I forgot to mention that my app then stops responding completely (permanent ANR) and I repeatedly get the SQLiteConnectionPool warning above only with increasing timeout time - it will remain in ANR for many hours (easily several 10k of seconds). This is a big pain in the ass for me. I have to manually kill the app to make it run again.

I try to use the singleton approach for SQLite (like described here: https://www.androiddesignpatterns.com/2012/05/correctly-managing-your-sqlite-database.html) but I have a problem that I extend my SQLiteHepler with various different code for various apps so I do not have "synchronized" getInstance method like in the example but rather check the global variable which holds my SQLiteOpenHelper instance for null and if equals null then I create new SQLiteOpenHelper instance.

In the meantime I solved the problem by not accessing the DB from my Java code and only using your plugin. But this is not ideal for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants