Skip to content

Commit

Permalink
issue 3238 - fix cpu 100% (#3569)
Browse files Browse the repository at this point in the history
* issue 3238 - fix cpu 100%

* issue 3238 - remove useless code
  • Loading branch information
PanternBao authored Dec 28, 2022
1 parent c68c60b commit 078b381
Showing 1 changed file with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,29 @@

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

public class UserSqlHighStat {

private static final int CAPACITY_SIZE = 1024;

private Map<String, SqlFrequency> sqlFrequencyMap = new ConcurrentHashMap<>();

private ReentrantLock lock = new ReentrantLock();


private StatSqlParser sqlParser = new StatSqlParser();

public void addSql(String sql, long executeTime, long startTime, long endTime) {
String newSql = this.sqlParser.mergeSql(sql);
SqlFrequency frequency = this.sqlFrequencyMap.get(newSql);
if (frequency == null) {
if (lock.tryLock()) {
try {
frequency = new SqlFrequency();
frequency.setSql(newSql);
} finally {
lock.unlock();
}
} else {
while (frequency == null) {
frequency = this.sqlFrequencyMap.get(newSql);
}
frequency = new SqlFrequency();
frequency.setSql(newSql);
SqlFrequency tmp = sqlFrequencyMap.putIfAbsent(newSql, frequency);
if (tmp != null) {
frequency = tmp;
}
}
frequency.setLastTime(endTime);
frequency.incCount();
//TODO setExecuteTime has thread safe problem
frequency.setExecuteTime(executeTime);
this.sqlFrequencyMap.put(newSql, frequency);
}


Expand Down

0 comments on commit 078b381

Please sign in to comment.