Reputation: 792
I have a module that is accessing a sqlite database to write all the data downloaded from a webservice. Because it takes a lot time inserting the rows, it is launched by a independent thread at the background so, the UI thread is secured. The problem is, this process, can be called while the database is still upgrading causing duplicated rows (because the data from the webservice is always the same plus new content)
I need something that can ask SQLite if its upgrading and wait until it ends to call the new upgrading. Any ideas aplying SOLID principles?
Upvotes: 0
Views: 30
Reputation: 1010
If you are running this on a background thread just check thread.isAlive().
Alternatively, just use a boolean flag and set it to true right before you start your thread.
I would go the boolean option beacuse there may be a short delay until your Thread is up and running, and if your main thread tries to start the thread twice in quick succession, it may get a "false" negative on thread.isAlive().
Hope this helps !
Upvotes: 1