IDEMPIERE-5355 Improve default trx name (FHCA-3765) (#1427)

Improve performance using StackWalker instead of Throwable->getStackTrace
This commit is contained in:
Carlos Ruiz 2022-08-05 03:46:11 +02:00 committed by GitHub
parent 9b812a315f
commit 464de082a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions

View File

@ -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();