public class SlowQueryListener extends Object implements QueryExecutionListener
onSlowQuery(ExecutionInfo, List, long) callback method
is called. The callback is called only once for the target query if it exceeds the threshold time.
NOTE:
ExecutionInfo.elapsedTime contains the time when callback is triggered which usually is the specified threshold time.
If you want to log or do something with AFTER execution that has exceeded specified threshold time, use normal
logging listener like following:
long thresholdInMills = ...
SLF4JQueryLoggingListener listener = new SLF4JQueryLoggingListener(){
@Override
public void afterQuery(ExecutionInfo execInfo, List queryInfoList) {
if (execInfo.getElapsedTime() >= thresholdInMills) {
super.afterQuery(execInfo, queryInfoList);
}
}
};
CommonsSlowQueryListener,
JULSlowQueryListener,
SLF4JSlowQueryListener,
SystemOutSlowQueryListener| Modifier and Type | Field and Description |
|---|---|
protected ScheduledExecutorService |
executor |
protected Map<ExecutionInfo,Long> |
inExecution |
protected long |
threshold |
protected TimeUnit |
thresholdTimeUnit |
protected boolean |
useDaemonThread |
DEFAULT| Constructor and Description |
|---|
SlowQueryListener() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterQuery(ExecutionInfo execInfo,
List<QueryInfo> queryInfoList) |
void |
beforeQuery(ExecutionInfo execInfo,
List<QueryInfo> queryInfoList) |
ScheduledExecutorService |
getExecutor() |
long |
getThreshold() |
TimeUnit |
getThresholdTimeUnit() |
protected void |
onSlowQuery(ExecutionInfo execInfo,
List<QueryInfo> queryInfoList,
long startTimeInMills)
Callback when query execution time exceeds the threshold.
|
void |
setThreshold(long threshHold) |
void |
setThresholdTimeUnit(TimeUnit thresholdTimeUnit) |
void |
setUseDaemonThread(boolean useDaemonThread)
When set to
true(default), the executor creates daemon threads to check slow queries. |
protected boolean useDaemonThread
protected ScheduledExecutorService executor
protected long threshold
protected TimeUnit thresholdTimeUnit
protected Map<ExecutionInfo,Long> inExecution
public void beforeQuery(ExecutionInfo execInfo, List<QueryInfo> queryInfoList)
beforeQuery in interface QueryExecutionListenerpublic void afterQuery(ExecutionInfo execInfo, List<QueryInfo> queryInfoList)
afterQuery in interface QueryExecutionListenerprotected void onSlowQuery(ExecutionInfo execInfo, List<QueryInfo> queryInfoList, long startTimeInMills)
execInfo - query execution infoqueryInfoList - query parameter infostartTimeInMills - time in mills when the query startedpublic void setThreshold(long threshHold)
public void setThresholdTimeUnit(TimeUnit thresholdTimeUnit)
public ScheduledExecutorService getExecutor()
public long getThreshold()
public TimeUnit getThresholdTimeUnit()
public void setUseDaemonThread(boolean useDaemonThread)
true(default), the executor creates daemon threads to check slow queries.useDaemonThread - use daemon thread or not. (default is true)Copyright © 2018. All rights reserved.