jdk1.5 before:
(New Exception ()). Getstacktrace () [2]. Getmethodname ()
(New Exception ()). Getstacktrace () [2]. GetClassName () ()
(New Exception ()). Getstacktrace () [2]. Getlinenumber ()
After jdk1.5
Thread.CurrentThread (). Getstacktrace () [2]. Getmethodname ()
Thread.CurrentThread (). Getstacktrace () [2]. GetClassName () ()
Thread.CurrentThread (). Getstacktrace () [2]. Getlinenumber ()
Actually look at the source code
Thread.CurrentThread (). Getstacktrace () is used (new Exception ()). Getstacktrace ()
As follows:
/** * Returns An array of stack trace elements representing the stack dump * of this thread. This method would return a zero-length array if * The thread has not started or has terminated. * If The returned array is of Non-zero length then the "the" the "the" the "the" the "the" the top of the stack, which is the most recent * method invocation in the sequence. The last element of the array * represents the bottom of the stack, which are the least recent method * invocation in the S Equence. * <p>if There is a security manager, and this thread are not * "Current thread", then the security manager ' s * &L T;tt>checkpermission</tt> method are called with A * <tt>runtimepermission ("Getstacktrace") </tt> Permission * to = if it ' s OK to get the stack trace. * <p>some virtual machines may, under Some circumstances, omit one * or more stack frames from the stack trace. In the extreme case, * a virtual machine that has no stack trace information concerninG * This thread are permitted to return a zero-length array from this *. * @return An array of <tt>stacktraceelement</tt>, and * each represents one stack frame. * * @throws SecurityException * If a security manager exists and their * <tt>checkPermission</tt> method doesn ' t Allow * Getting the stack trace of thread. * @see securitymanager#checkpermission * @see runtimepermission * @see throwable#getstacktrace * * @since 1.5/Public St Acktraceelement[] Getstacktrace () {if (this!= thread.currentthread ()) {//Check for getstacktrace permission Securityma Nager security = System.getsecuritymanager (); if (security!= null) {security.checkpermission (securityconstants.get_stack_trace_permission);} if (!isalive ()) {Retu RN Empty_stack_trace; Return Dumpthreads (new thread[] {this}) [0]; else {//Don ' t need JVM help for the current thread return (new Exception ()). Getstacktrace ();}