get Top Trace Element - Java java.lang

Java examples for java.lang:Throwable

Description

get Top Trace Element

Demo Code


//package com.java2s;

public class Main {
    public static StackTraceElement getTopTraceElement(
            StackTraceElement topTraceElement) {
        StackTraceElement[] stackElements = Thread.currentThread()
                .getStackTrace();/*www . j  ava2s  .c  o m*/
        if (stackElements != null) {
            for (int i = 0; i < stackElements.length && i < 10; i++) {
                StackTraceElement ele = stackElements[i];
                if (ele == topTraceElement)
                    break;
                String str = ele.toString();
                if (isTracerMethod(str))
                    continue;
                return ele;
            }
        }
        return null;
    }

    private static boolean isTracerMethod(String str) {
        return str.startsWith("net.juniper.jmp.tracer")
                || str.startsWith("net.juniper.jmp.monitor")
                || str.startsWith("java.lang.Thread.getStackTrace");
    }
}

Related Tutorials