Try to optimize my application database work.
During database synchronization my application runs a big package of ‘delete’ and ‘insert’ commands inside one transaction. After the transaction ‘COMMIT’ application run ‘VACUUM’ command. VACUUM works fine, but sometimes it takes a lot of time. So I decided to move 'VACUUM' execution in parallel thread. And here is going something wrong. In other thread I get “database is locked”.
What I do:
1.Close database after successful ‘COMMIT’.
2.Start separate method that open and close database again with 'VACUUM'.
In the same thread of ‘COMMIT’ the 'VACUUM' works fine, but in separate thread the same method get “database is locked” error. I definitely can say that no other process works with closed database since database synchronization is a logically separate application process.
What I do wrong?
[connection closeDb];
[connection release];
if(!rollBackTransaction && commitSuccess){
// The commented code block doesn't work - "database is locked" error
// NSThread *thread=[[NSThread alloc] initWithTarget:self selector:@selector(runVacuumForDataBase:) object:_dbFileName];
// [thread start];
[self runVacuumForDataBase:_dbFileName]; // <-- This works fine
}