0

My app has several AsyncTaskRunners which are constantly access the database. I keep getting ThreadPool errors because of a closed database instance. Originally I had a new instance opened and then closed again, each with a different name every time. So every method that accessed the database would open its very open instance do whatever and then close that instance.

I was hoping that it would have been more efficient to open a single instance and then not close it so that every method within the AsyncTask would just do its thin with the database.

Is there a way to open a database instance when the app starts and not close it, and then get & put throughout the entire application just be referencing that instance?

Or is there a way to open an instance for my AsyncTaskRunner class so that all methods in that class can talk to the database?

I have tried initializing a database instance at the beginning of the class with

SQLDatabase db;

and then later in the doInBackground() I would open an instance of db and not close it. Then the various methods would try to talk to the db but with no success.

PedroHawk
  • 622
  • 5
  • 19
  • Use [Singleton](http://www.tutorialspoint.com/java/java_using_singleton.htm) Class concept for creating DB object. – Anil Jadhav Jul 08 '14 at 08:39
  • this source is very good http://stackoverflow.com/a/19996964/3193867 – SMR Jul 08 '14 at 08:41
  • Thanks. I do not know why that article never came up in the three days that I have spent on this problem. –  Jul 08 '14 at 08:51

0 Answers0