You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2020/05/13 03:51:41 UTC
[Bug 58489] QueryStatsComparator throws IllegalArgumentException:
Comparison method violates its general contract!
https://bz.apache.org/bugzilla/show_bug.cgi?id=58489
bill_t_wang@hotmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bill_t_wang@hotmail.com
--- Comment #10 from bill_t_wang@hotmail.com ---
Created attachment 37237
--> https://bz.apache.org/bugzilla/attachment.cgi?id=37237&action=edit
extract the information to sort on from the QueryStats and sort on that
information
I resolved this bug in SlowQueryReport,using the second proposal by Felix
Schumacher -- "extract the information to sort on from the QueryStats and sort
on that information".
1, add a constructor in the inner class QueryStats for QueryStats clone
/**
* Create a new QueryStats object based on another QueryStats object.
* For resolving Bug 58489,
https://bz.apache.org/bugzilla/show_bug.cgi?id=58489
* @param qs
*/
QueryStats(QueryStats qs){
this.query = qs.query;
this.nrOfInvocations = qs.nrOfInvocations;
this.maxInvocationTime = qs.maxInvocationTime;
this.maxInvocationDate = qs.maxInvocationDate;
this.minInvocationTime = qs.minInvocationTime;
this.minInvocationDate = qs.minInvocationDate;
this.totalInvocationTime = qs.totalInvocationTime;
this.failures = qs.failures;
this.prepareCount = qs.prepareCount;
this.prepareTime = qs.prepareTime;
this.lastInvocation = qs.lastInvocation;
}
2, modify method removeOldest
protected void removeOldest(ConcurrentHashMap<String,QueryStats> queries) {
ArrayList<QueryStats> list = new ArrayList<>(queries.values());
//For resolving Bug 58489,
https://bz.apache.org/bugzilla/show_bug.cgi?id=58489
//make a list of cloned QueryStats objects
for(int i=0; i<list.size(); i++){
list.set(i, new QueryStats(list.get(i)));
}
//
Collections.sort(list, queryStatsComparator);
int removeIndex = 0;
while (queries.size() > maxQueries) {
String sql = list.get(removeIndex).getQuery();
queries.remove(sql);
if (log.isDebugEnabled()) log.debug("Removing slow query, capacity
reached:"+sql);
removeIndex++;
}
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org