Created
October 5, 2017 20:26
-
-
Save ern/34e44b9933a3ff6f31088a91a578ae9f to your computer and use it in GitHub Desktop.
Simulate a slow resource
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void traceSimulateDelay(long delay) { | |
// log the caller | |
String thisClassName = this.getClass().getName(); | |
StackTraceElement[] ste = Thread.currentThread().getStackTrace(); | |
StringBuilder callee = new StringBuilder("PERFORMANCE[-{}] called by "); | |
for (int i = 2; i <= ste.length; i++) { | |
// 0 is Thread.getStackTrace() | |
// 1 is this method | |
String className = ste[i].getClassName(); | |
String shortClassName = className.substring(className.lastIndexOf(".") + 1); | |
callee.append(shortClassName).append(".").append(ste[i].getMethodName()).append(":").append(ste[i].getLineNumber()); | |
if (thisClassName.equals(className)) { | |
callee.append(">"); | |
} else { | |
break; | |
} | |
} | |
M_log.trace(callee.toString(), delay); | |
// simulate a long query | |
try { | |
Thread.sleep(delay); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment