Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.sql.Statement;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand All @@ -40,11 +41,13 @@ public class StatementFinalizer extends AbstractCreateStatementInterceptor {
protected List<StatementEntry> statements = new LinkedList<>();

private boolean logCreationStack = false;
private int createStatementCount=0;
Comment thread
Fisherman110 marked this conversation as resolved.

@Override
public Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time) {
try {
if (statement instanceof Statement) {
clearEntry();
statements.add(new StatementEntry((Statement)statement));
}
}catch (ClassCastException x) {
Expand Down Expand Up @@ -93,6 +96,22 @@ public void reset(ConnectionPool parent, PooledConnection con) {
super.reset(parent, con);
}

public void clearEntry() {
if(createStatementCount%10!=0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you want to check every add?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function clearEntry() is called when a new statement is created and will be add to the list. Check line 50 in StatementFinalizer.java

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear opration invoked every ten times

createStatementCount++;
return;
}else {
createStatementCount=0;
Iterator<StatementEntry> iterator = statements.iterator();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done with List.removeIf()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank u, I don't know the removeIf feature before

while (iterator.hasNext()) {
StatementEntry st = iterator.next();
if(st.getStatement()==null || st.getStatement().isClosed()) {
iterator.remove();
}
}
}
}

protected class StatementEntry {
private WeakReference<Statement> statement;
private Throwable allocationStack;
Expand Down