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