Skip to content

fix for Bug 62432 , clear invalid Entry for org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer#941

Open
Fisherman110 wants to merge 1 commit intoapache:mainfrom
Fisherman110:tomcatM-feature
Open

fix for Bug 62432 , clear invalid Entry for org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer#941
Fisherman110 wants to merge 1 commit intoapache:mainfrom
Fisherman110:tomcatM-feature

Conversation

@Fisherman110
Copy link

The original proposal Bug 62432

The StatementFinalizer keeps a list of statements which he closes
if they're still open when the connection is closed. The list keeps
weak references to the statements, so when the statement is closed
by client code, it can be garbage collected and will not be closed
by the StatementFinalizer.

However, the StatementFinalizer keeps the references to the Statements
indirectly through instances of StatementFinalizer$StatementEntry.
These instances are not cleaned up even when the statements they refer
to have long been closed. Mostly this does not seem to be a problem when
connections are closed quickly.

But we have had long running jobs that created many Statements with
the same connection where the instances of (empty)
StatementFinalizer$StatementEntry finally brought the VM to its knees.

The useless instances of StatementFinalizer$StatementEntry kept
around in the statement list constitute a memory leak in my opinion.

What's new?

A new feature to address the memory leak for StatementFinalizer$statements.
When a new Statement is created, it invokes the function called clearEntry().
The clearEntry function will clean those invalid (null or have been closed)
StatementEntry instances in the list every ten times.

protected List<StatementEntry> statements = new LinkedList<>();

private boolean logCreationStack = false;
private int createStatementCount=0;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's unnecessary to initialize instance variables, since they're being initialized with their default value. In this case: 0

return;
}else {
createStatementCount=0;
Iterator<StatementEntry> iterator = statements.iterator();
Copy link
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()

}

public void clearEntry() {
if(createStatementCount%10!=0) {
Copy link
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants