bildwelt
E2E FORUM
E2E Bridge E2E Commerce

SQLite "Database is locked" on multi thread insert statement

E2E Forum Modeling & Development SQLite "Database is locked" on multi thread insert statement

This topic contains 2 replies, has 3 voices, and was last updated by  Alfred 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3304

    cporciuncula
    Participant

    Hi,

    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?

    #3305

    Jakub
    Moderator

    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.


    Regards,
    Jakub

    #3306

    Alfred
    Moderator

    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.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.