I've found several posts with instructions of how to kill java thread with jdb http://www.rhcedan.com/2010/06/22/killing-a-java-thread/ or on SO. This works.
Now I want to kill thread with Intellij-IDEA debugger. Is it possible to do?
There is a little icon on the right side of the Debug view:
This will open 'Threads' tab and there you can right-click on some of them and select 'Interrupt' (and press F9 if you are sleeping on some breakpoint).
The accepted answer is now outdated (at least it is different for me in IntelliJ 2022.3.2). Just in case anyone (like me) stumbles upon it, there is a button at the right side of the debugger that allows you to show threads (it is disabled by default).
see image below:
Then you'll be able to select the thread you want to modify through the debugger by right clicking it.
Related
Before asking - I have checked similar questions and was not able to achieve my goal so far. My trouble resulted from CTRL+F2 not working in Eclipse. Therefore I spent time looking for shortcut settings and tested solutions here
What is the short cut in eclipse to terminate debugging/running?
or here
Eclipse Terminate Keyboard Shortcut
yet none of this seems to work.
By now I have discovered the reason why, so here is the question:
Why is my context menu Run > Terminate greyed out, even though a Java application is launched?
The steps I am taking are:
1) ALT+R to open Run context menu
2) N to open Run Configurations
3) ALT+R to run my configuration
4) The application launches as expected
5) Now I switch back to Eclipse and press ALT+R again - Terminate is greyed out, while the application is running.
Why is that?
Note:
This is the reason for the terminate shortcut not working properly, because this context menu entry is annotated with the according shortcut, as long as it is greyed out nothing will ever happen.
I am also in the Debug perspective.
Pressing the red rectangled Stop UI element will still kill the application, as it should. All the while the context menu entry in Run remains greyed out. Why would these two even map to different things?
Thanks in advance for any kind of insight.
This is only enabled when you have selected the application in the Debug view.
I was able to achieve what I was looking for with help of #greg-449.
The setup is now as follows:
In Eclipse open Window > Preferences > General > Keys > Show View (Debug) set a shortcut to ALT+ SHIFT + F2 as suggested in the sources I linked. Set binding to In Windows.
Now after launching it is possible to press the newly set shortcut to open debug and after that the Terminate context menu will become available, even though there is apparently no way to call Terminate all which is what the UI element does.
In conclusion, it is complicated, but at least it works. Being forced to manage launches this way still seems absurd to me, however.
When I try to use the debugger (F7) in NetBeans, it does not seem to work properly for me. While normally it would move step by step through the program, my debugger instead opens a new tab called "scanner.java" the second time I press F7. If someone could help me with this issue, that'd be great!
According to the documentation (see all shortcuts here)
F7 is for stepping into
F8 is for stepping over
So, it is behaving correctly. When you step into some code the debugger moves into that calls stack.
If you want to "move step by step through the program" you need to press F8
Further readings
Oracle documentation: Running and Debugging Java Application Projects, Table 9-3 Debugging Step Commands and Icons
So there is a small java program to add two numbers.
There is one break-point.
I used Debug as -> Java Application.
But still, Step Into, Step Over, Resume, Suspend and Terminate buttons are disabled in my eclipse.
See below:
Debugger recognized the breakpoint at int b = 3 but still the buttons are disabled.
Everything was working fine yesterday.
What should be the cause?
Possibles solutions and cause here.
The commands got disabled, probably from previous customization, (check General -> Keys) but I wouldn't think this can be the only reason to be cause of this issue.
Hope this helps you out.
I have met the same issue and fixed it. The following are the possible solutions:
Make sure that your skip all break point option is disabled
Reset your debug perspective in perspective options.
Make sure to restart eclipse after doing above things
When I run my code in the debugger in Eclipse, it jumps to the various breakpoints I have set, but when I terminate the debugging session, it does not return me to my previous code editing location.
How can I make it return me to where I was working after a debugging session?
In Eclipse there are buttons to select the Perspective (eg, Resources, Java, Debug, etc). When you are on Debug, the button Debug is on. If you want to go back to another Perspective, just press the corresponding button.
Read more here and here.
Short answer:
It's not possible (out of the box).
An Eclipse bug ticket exists, requesting this feature:
Bug 46336
Alternatively you can easily switch perspectives with:
Ctrl + F8.
See Shotcuts tutorial
or install a plugin:
Eclipse plugin
Sorry for the strange name of my question. I don't know how to look for this because I don't know how these things are called.
There's a features in Visual Studio at least where you can click on the left of the code and set a starting point which is a big red dot. Then you run the program and you can trace the steps by pressing f8 or f5 (different f's really) and you see the variable values on each step etc. I find it extremely useful because I can see where an error occurs and how the program behaves.
I have no idea what this is called and I want to ask is there such a thing in NetBeans IDE 8.0.2 or jGrasp or any java compiler?
Sorry if anything sounds stupid, I'm kind of a newbie.
Thank you all
Most IDEs have debugging functionality built in.
In Netbeans, you can easily add/remove a break point by simply clicking the line number on right side of the source editor (you can also do via the editor popup menu)
You start the debugger through F5 (ShiftF5 for debug the current file) or via the debug icon on the toolbar
You can use F8 to step over the command/method call, F7 to step into a method. You can resume running the program using F5 while the debugger is running.
See Debugger and Profiler and Using the Visual Debugger in NetBeans IDE for more details
Finding how to do this in your IDE is pretty easy, see the other answers.
What is a bit more difficult is debugging an external (and/or) remote Java program in your IDE. Here it is how to do that with Eclipse: http://www.ibm.com/developerworks/library/os-eclipse-javadebug/. I guess other IDEs are similar. If you test via Maven/Surefire, you have a simple flag to do the same: http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html