I’m trying to use “CreateThread” stereotype for multi-threading. My scenario is with writing into sqlite. But the problem is I don’t know how to set an option to make sqlite inserts thread safe. Is there any way that we can do this?
Hi, first of all “Create Thread” is deprecated and shouldn’t be used. Regarding SQLite: it’s designed to handle concurrent reads well but does not handle concurrent writes at all. As soon as one thread acquires a write lock, all others are blocked (SQLite has only file-level lock) until this thread releases the lock (usually by committing its transaction). You could try committing the transaction after each insert but that would a) have a really bad performance, b) interfere with the internal transaction handling, so I recommend against it.
In the documentation SQLite Deployment Options it is explained how-to increase the busy timeout. If you increase the busy timeout you still can not write concurrent to the database but SQLite it self will retry the write till the timeout is reached.
The recommended alternative to “Create Thread” is to use for each thread a new persistent state object.