Trace Java method execution

422 views Asked by At

I am having a hard time finding a way to trace a method execution (ex: methods being called at execution..)

Here is the code snippet I want to trace:

@GetMapping("/test")
        public String test(){

            String jsonString = "{\"key1\":\"value1\",\"type\":\"Booking\",\"sid\":\"A43521\",\"region\":\"ASIA\","
                + "\"fetchFromFile\":\"false\",\"service\":\"true\",\"isEom\":\"true\",*#@!}";
            String response = JsonSanitizer.sanitize(jsonString);
            return response;
        }

I'd like to know that the method sanitize of JsonSanitizer class has been called ..

I tried running jstack, but I don't see any occurences of JsonSanitizer.sanitize method in the stack traces.

Thanks in advance

1

There are 1 answers

2
Adriaan Koster On

You can either add log statements in your code, which write information to a log file or System.out for example, or you can run the application in debug mode and add a breakpoint in the code from where you want to start tracking what happens. When the code execution reaches the breakpoint, the debugger will pause execution and you can step through/in/out the statements one by one.