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.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -131,13 +132,14 @@ public class Trx
|
|||
if (prefix == null || prefix.length() == 0) {
|
||||
prefix = "Trx";
|
||||
if (MSysConfig.getBooleanValue(MSysConfig.TRX_AUTOSET_DISPLAY_NAME, false)) {
|
||||
StackTraceElement[] st = new Throwable().fillInStackTrace().getStackTrace();
|
||||
for (StackTraceElement ste : st) {
|
||||
if (! Trx.class.getName().equals(ste.getClassName())) {
|
||||
displayName = ste.getClassName().concat("_").concat(ste.getMethodName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
|
||||
Optional<String> stackName = walker.walk(frames -> frames.map(
|
||||
stackFrame -> stackFrame.getClassName() + "." +
|
||||
stackFrame.getMethodName() + ":" +
|
||||
stackFrame.getLineNumber())
|
||||
.filter(f -> ! f.startsWith(Trx.class.getName() + "."))
|
||||
.findFirst());
|
||||
displayName = (stackName.orElse(null));
|
||||
}
|
||||
}
|
||||
prefix += "_" + UUID.randomUUID(); //System.currentTimeMillis();
|
||||
|
|
Loading…
Reference in New Issue