Skip to content

Instantly share code, notes, and snippets.

@ggiraldez
Created April 3, 2014 21:53
Show Gist options
  • Save ggiraldez/9963666 to your computer and use it in GitHub Desktop.
Save ggiraldez/9963666 to your computer and use it in GitHub Desktop.
SQLite JDBC autoCommit race condition
Class.forName('org.sqlite.JDBC')
import groovy.sql.Sql
import java.sql.*
def sql = Sql.newInstance('jdbc:sqlite::memory:', [:] as Properties, 'org.sqlite.JDBC')
sql.execute('drop table if exists test')
sql.execute('create table test (key integer primary key, value string)')
def connection = sql.connection
connection.autoCommit = false
def query = "insert into test (value) values ('foo')"
def lock = new Object()
def t = { ->
def count = 10000
while (count-- > 0) {
//synchronized(lock) {
def statement = connection.prepareStatement(query);
statement.executeUpdate();
Thread.sleep(1);
connection.commit();
statement.close();
//}
}
}
def t1 = Thread.start(t)
def t2 = Thread.start(t)
t1.join()
t2.join()
connection.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment