Is there a tool I can use to see what parts of the code are in which thread (colour code it or something)? I'm mostly concerned about EDT, but writing that isOnEventDispatchThread()-ish command every other line and then keeping track of it's output while the program is running is tedious and time consuming.
The major problem I'd see with this is code that can be called from any thread, such as constructors. You can however use Eclipse's debugger at runtime. Simply run the program in the debugger until a breakpoint or with manual pause then look at the "debug" view that is generally in the upper left. You'll see threads and may select one to jump to its location.
Related
I want to see what lines of code are being executed in my Java program when it runs and terminates. One way I can do this is by using an IDE such as IntelliJ or Eclipse and setting a break point in the main method, then going through each line of code one after another using the step-over and step-into buttons. This becomes extremely tedious to do after a while though, because the program freezes every time I want to know what line of code is executed next.
Is there another way to see what's happening in my Java program, other than using an IDE debugger and setting breakpoints? I would also like to be able to use my program like a normal user would be able to (i.e. not being paused every few seconds because of my IDE).
I have a problem while debugging in IntelliJ IDEA, it hangs in debug mode on break point in listeners in javafx application. I tried to increase heap space, but it's not help. Maybe someone had such problem too, please, suggest me what to do.
Set this as a VM parameter:
-Dsun.awt.disablegrab=true
It will mess up drag-and-drop, and leave an artifact on your screen while the debugger is paused - but it will let you debug. It happens whenever you block the JavaFX thread.
This can happen for a simple reason: The application has a lock on the desktop, for example a modal dialog or a popup or an open menu. Then it stops in a breakpoint. This notifies the IDE. Now the IDE tries to do something on your desktop but can't since the application still has a lock on the whole desktop -> deadlock.
You can use a tool like Chronon which records the whole program and lets you move back and forth on the timeline.
The last option is logging or poor man's debugger (System.out) instead.
[EDIT]
it's hard to check with System.out which of 20 parameters not equal.
It's actually pretty easy:
System.out.println("check");
if(!a1.equals(b2)) System.out.println(a1+"!="+b1);
Then duplicate the last line. That way, you will only get output when something is actually interesting (and not for the 19 equal parameters). Add some patterns to the output if you can't distinguish aX from aY (i.e. both are true):
if(!a1.equals(b2)) System.out.println("a1:"+a1+"!="+b1);
I have the following 2 questions regarding Eclipse debugger:
The application that I work on consists of a large number of Maven modules. Is it possible to set a break point on a whole module?
I often have to work on applications that I have no prior knowledge of, and thus don't know where to put a breakpoint. Is there a good place to set a break point in such apps to stop the debugger? Then I can just use the step debugger to trace and see what the code is doing.
Thanks
No, breakpoints are a point, namely a line, in the code where you would like execution to stop. The JVM has no notion of separate Maven modules, so cannot break on that basis.
What information do you start with? Presumably you're not literally looking at a .zip of code you know nothing about. You can place a breakpoint in the main() method to break (almost) as soon as the application starts, or identify other core classes and place breakpoints in them. Other than the actual application entry point (main() and so on), there is no standard "good" place to put a breakpoint in order to see what the code is doing.
I am debugging an application with lots of threads. My breakpoints are set to suspend the whole VM.
When a thread hits one of the breakpoints, I then want to use Step Over. But this appears to resume the whole VM, until that step completes.
It'd really help if I could step just the single thread that hit the breakpoint.
Is there any way to do this in IntelliJ 11.1 / Java 6? (Hope I'm not missing something obvious...)
This feature was added in IntelliJ 16 (the issue CrazyCoder referenced in his answer was resolved)
More details here:
https://blog.jetbrains.com/idea/2016/02/intellij-idea-16-eap-improves-debugger-and-adds-git-worktree-support/
NetBeans can resume individual threads. While in debug mode, you can resume a thread from the left thread list by pressing a small button shaped like Play (►) near the thread.
Currently there's no such possibility because it may lead to deadlocks. You may vote for IDEA-43728 though.
I'm modifying a rather big codebase and I'm in the process of debugging. My code doesn't terminate, so I don't get a stacktrace. I tried to isolate the trouble code with breakpoints, but unfortunately it runs through sections that are executed all the time (transaction manager), so I'm clicking to death. Furtermore, i get the impression that the code breaks only under certain conditions, but runs fine most of the time.
Is there a way in Intellij to see the last method that was / the current method that is executed?
thanks
You can use BTrace, a tracing tool, to print out the name of every method entered in your program. There is a sample script that comes with BTrace, called AllMethods, which does just that.
All of you have to do is start your java process and then run the BTrace script against the JVM's PID. It will print out every method entered. You can restrict it to certain packages if you like. For more information about using BTrace check out this tutorial.
Use a profiler. It will give you a breakdown of which methods are executing, how much time your program spends in each method etc etc. It should be quite easy to find out from there where your program is spending its time.
JProfiler is an example. I think it has a trial / demo version which is fully functional.