I’m using JPA (Hibernate) and Spring and have a EntityManagerFactory but I need a SessionFactory. How can I convert a byte array to a hex string representation?
Oct 13

The StackTraceElement class can be used to get details about the call stack.

The following example shows how it can be used to view the call stack and determine where a method was called from.


public class WhoCalledMe
{

	public static void main(String[] args)
	{
		f();
	}

	public static void f()
	{
		g();
	}

	public static void g()
	{
		showCallStack();
		System.out.println();
		System.out.println(
			"g() was called by "+whoCalledMe());
	}

	public static String whoCalledMe()
	{
		StackTraceElement[] stackTraceElements =
			Thread.currentThread().getStackTrace();
		StackTraceElement caller = stackTraceElements[4];
	    String classname = caller.getClassName();
	    String methodName = caller.getMethodName();
	    int lineNumber = caller.getLineNumber();
		return classname+"."+methodName+":"+lineNumber;
	}

	public static void showCallStack()
	{
		StackTraceElement[] stackTraceElements =
			Thread.currentThread().getStackTrace();
		for (int i=2 ; i<stackTraceElements.length; i++)
		{
			StackTraceElement ste = stackTraceElements[i];
		    String classname = ste.getClassName();
		    String methodName = ste.getMethodName();
		    int lineNumber = ste.getLineNumber();
		    System.out.println(
		    	classname+"."+methodName+":"+lineNumber);
		}
	}
}
del.icio.us:Can I get details of the call stack in Java, such as to find where a method was called from? digg:Can I get details of the call stack in Java, such as to find where a method was called from? spurl:Can I get details of the call stack in Java, such as to find where a method was called from? wists:Can I get details of the call stack in Java, such as to find where a method was called from? simpy:Can I get details of the call stack in Java, such as to find where a method was called from? newsvine:Can I get details of the call stack in Java, such as to find where a method was called from? blinklist:Can I get details of the call stack in Java, such as to find where a method was called from? furl:Can I get details of the call stack in Java, such as to find where a method was called from? reddit:Can I get details of the call stack in Java, such as to find where a method was called from? fark:Can I get details of the call stack in Java, such as to find where a method was called from? blogmarks:Can I get details of the call stack in Java, such as to find where a method was called from? Y!:Can I get details of the call stack in Java, such as to find where a method was called from? smarking:Can I get details of the call stack in Java, such as to find where a method was called from? magnolia:Can I get details of the call stack in Java, such as to find where a method was called from? segnalo:Can I get details of the call stack in Java, such as to find where a method was called from? gifttagging:Can I get details of the call stack in Java, such as to find where a method was called from?

written by objects \\ tags: , ,


Leave a Reply

You must be logged in to post a comment.