'Springboot Sqlite database file locked error with no multithreading

All answers I have come across on the sqlite database file getting locked problem involve simultaneous readers and writers. But I'm facing the issue even when running in single threaded mode, in an Integration test that I'm running with

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest

Update: Without even understanding why it should help, I added synchronized statements in my code reading and writing to the database and after that the error did not happen.

Since springboot doesn't natively support sqlite, I have used a custom dialect file in

spring.jpa.database-platform=com.springboot.sqlite.SQLDialect

FWIW, I also have

spring.datasource.maxActive = 1

and also I have set write-ahead logging:

jdbcTemplate.execute("pragma journal_mode=WAL");

My test just runs several read and write operations in sequence but it fails with

The database file is locked (database is locked); nested exception is org.sqlite.SQLiteException: [SQLITE_BUSY]  The database file is locked (database is locked)

at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1542)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:393)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:558)

Any help is much appreciated.



Solution 1:[1]

Try adding the following configuration to application.properties

spring.datasource.hikari.maximum-pool-size=1

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 meng lingjie