Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 14839ba

Browse filesBrowse files
tildedavexerial
authored andcommitted
Skip synchronized block in close() if ResultSet is already closed (xerial#358)
Fixes xerial#349 From profiling our app in production we noticed that our finalizer thread was periodically getting the synchronized lock on the DB (introduced in xerial#215). By the time our ResultSet hits the finalizer queue the ResultSet has already been closed, so there's no need to acquire the lock to reset the statement pointer. As part of this I've removed what I believe to be dead code around checking for the nullability of the stmt member on the ResultSet.
1 parent ed45927 commit 14839ba
Copy full SHA for 14839ba

2 files changed

+21-6Lines changed: 21 additions & 6 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/org/sqlite/core/CoreResultSet.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/sqlite/core/CoreResultSet.java
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,18 @@ public void close() throws SQLException {
120120
cols = null;
121121
colsMeta = null;
122122
meta = null;
123-
open = false;
124123
limitRows = 0;
125124
row = 0;
126125
lastCol = -1;
127126
columnNameToIndex = null;
128127

128+
if (!open) {
129+
return;
130+
}
131+
129132
DB db = stmt.getDatbase();
130133
synchronized (db) {
131-
if (stmt == null) {
132-
return;
133-
}
134-
135-
if (stmt != null && stmt.pointer != 0) {
134+
if (stmt.pointer != 0) {
136135
db.reset(stmt.pointer);
137136

138137
if (closeStmt) {
@@ -141,6 +140,8 @@ public void close() throws SQLException {
141140
}
142141
}
143142
}
143+
144+
open = false;
144145
}
145146

146147
protected Integer findColumnIndexInCache(String col) {
Collapse file

‎src/test/java/org/sqlite/ResultSetTest.java‎

Copy file name to clipboardExpand all lines: src/test/java/org/sqlite/ResultSetTest.java
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,18 @@ public void testSelectWithTableNameNowNotFindWithTableName()
140140
resultSet.findColumn("test.id");
141141
}
142142

143+
@Test
144+
public void testCloseStatement()
145+
throws SQLException {
146+
ResultSet resultSet = stat.executeQuery("select test.id from test");
147+
148+
stat.close();
149+
150+
assertTrue(stat.isClosed());
151+
assertTrue(resultSet.isClosed());
152+
153+
resultSet.close();
154+
155+
assertTrue(resultSet.isClosed());
156+
}
143157
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.