IDEMPIERE-5355 Improve default trx name (FHCA-3765) (#1427)
Improve performance using StackWalker instead of Throwable->getStackTrace
This commit is contained in:
parent
9b812a315f
commit
464de082a5
|
@ -26,6 +26,7 @@ import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -131,13 +132,14 @@ public class Trx
|
||||||
if (prefix == null || prefix.length() == 0) {
|
if (prefix == null || prefix.length() == 0) {
|
||||||
prefix = "Trx";
|
prefix = "Trx";
|
||||||
if (MSysConfig.getBooleanValue(MSysConfig.TRX_AUTOSET_DISPLAY_NAME, false)) {
|
if (MSysConfig.getBooleanValue(MSysConfig.TRX_AUTOSET_DISPLAY_NAME, false)) {
|
||||||
StackTraceElement[] st = new Throwable().fillInStackTrace().getStackTrace();
|
StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
|
||||||
for (StackTraceElement ste : st) {
|
Optional<String> stackName = walker.walk(frames -> frames.map(
|
||||||
if (! Trx.class.getName().equals(ste.getClassName())) {
|
stackFrame -> stackFrame.getClassName() + "." +
|
||||||
displayName = ste.getClassName().concat("_").concat(ste.getMethodName());
|
stackFrame.getMethodName() + ":" +
|
||||||
break;
|
stackFrame.getLineNumber())
|
||||||
}
|
.filter(f -> ! f.startsWith(Trx.class.getName() + "."))
|
||||||
}
|
.findFirst());
|
||||||
|
displayName = (stackName.orElse(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prefix += "_" + UUID.randomUUID(); //System.currentTimeMillis();
|
prefix += "_" + UUID.randomUUID(); //System.currentTimeMillis();
|
||||||
|
|
Loading…
Reference in New Issue