IDE hangs in debug mode on break point in java fx application - java

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);

Related

How to track down seemingly random crashes in Java?

While doing some homework that works with some swing gui components, my program started crashing seemingly at random. That is, it starts, runs for a short time, and then crashes. I don't get any errors in the console, it's just a straight up crash.
I don't doubt that it is something I wrote, and I'm more than happy to show code if anyone wants to look at it, but is there anything that I can do myself to track down what might be the cause of my crashes?
Some other information that might be useful:
I'm using eclipse, and the debugger doesn't seem to do anything that helps me with this (program still crashes).
I didn't notice any issues like this until I started to add event handling.
I'm using Windows 10.
Occasionally, nothing is drawn in the window I create. Exiting and then running the program again will cause it to work.
Some possible heuristics:
Crashes that occur seemingly at random suggest incorrect synchronization; look for event dispatch thread violation using one of the approaches cited here.
Verify that all exception handlers produce diagnostic output; run from the command line to ensure that diagnostic output has not been inadvertently redirected.
Try running under the aegis of a different debugger, e.g. NetBeans.
Try running under the aegis of a profiler.
Try a different version of the JDK/JRE.
Try a different host OS.

Check thread eclipse plugin

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.

IntelliJ debugging: Suspend whole VM then step on single thread

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.

Eclipse pausing without a breakpoint on getting session code

While debugging, my Eclipse pause on same line every time. I read this Eclipse pausing without a breakpoint, but there are no exceptions in my console. I also read this Why does my Eclipse project have phantom debugger breakpoints?, but it doesn't help too.
The code that pauses debugger without breakpoint is this:
Query query = sessionFactory.getCurrentSession().createQuery(hql);
I think there's no problem with createQuery(). Whenever getCurrentSession() called, my Eclipse pauses. Why is this happening?
Look into concurrency. Maybe ur running into situations like deadlock. It happens when two objects are not locked in the same order, causing two different threads to be waiting for each other to release other object.
At this point it appears that the entire program has paused. Maybe its whats happening, but cant say for sure until I can see the code.
Sometimes I face this kind of problem and everytime I end up finding out that my java code is not synchronized with my .class, this happens when I'm in remote debugging. Try to close your eclipse, clean your project and then try again. If you're debugging remotely, update your source codes.
Cheers!
Simple. Application always multithreading.. Obvously that application stop in another thread. When you analyze on which tread Eclipse stop and click on this thread - you found that Eclipse starts to react on command.

Java app makes screen display unresponsive after 10 minutes of user idle time

I've written a Java app that allows users to script mouse/keyboard input (JMacro, link not important, only for the curious). I personally use the application to automate character actions in an online game overnight while I sleep. Unfortunately, I keep coming back to the computer in the morning to find it unresponsive. Upon further testing, I'm finding that my application causes the computer to become unresponsive after about 10 minutes of user idle time (even if the application itself it simulating user activity). I can't seem to pin-point the issue, so I'm hoping somebody else might have a suggestion of where to look or what might be causing the issue.
The relevant symptoms and characteristics:
Unresponsiveness occurs after user is idle for 10 minutes
User can still move the mouse pointer around the screen
Everything but the mouse appears frozen... mouse clicks have no effect and no applications update their displays, including the Windows 7 desktop
I left the task manager up along the with the app overnight so I could see the last task manager image before the screen freezes... the Java app is at normal CPU/Memory usage and total CPU usage is only ~1%
After moving the mouse (in other words, the user comes back from being idle), the screen image starts updating again within 30 minutes (this is very hit and miss... sometimes 10 minutes, sometimes no results after two hours)
User can CTRL-ALT-DEL to get to Windows 7's CTRL-ALT-DEL screen (after a 30 second pause). User is still able to move mouse pointer, but clicking any of the button options causes the screen to appear to freeze again
On some very rare occasions, the system never freezes, and I come back to it in the morning with full responsiveness
The Java app automatically stops input scripting in the middle of the night, so Windows 7 detects "real" idleness and turns the monitors into Standby mode... which they successfully come out of upon manually moving the mouse in the morning when I wake up, even though the desktop display still appears frozen
Given the symptoms and characteristics of the issue, it's as if the Java app is causing the desktop display of the logged in user to stop updating, including any running applications.
Programming concepts and Java packages used:
Multi-threading
Standard out and err are rerouted to a javax.swing.JTextArea
The application uses a Swing GUI
awt.Robot (very heavily used)
awt.PointerInfo
awt.MouseInfo
System Specs:
Windows 7 Professional
Java 1.6.0 u17
In conclusion, I should stress that I'm not looking for any specific solutions, as I'm not asking a very specific question. I'm just wondering if anybody has run into a similar problem when using the Java libraries that I'm using. I would also gladly appreciate any suggestions for things to try to attempt to further pinpoint what is causing my problem.
Thanks!
Ross
PS, I'll post an update/answer if I manage to stumble across anything else while I continue to debug this.
Update: my app involved multi-threaded processes each initializing their own Robot objects and creating input events asynchronously. I refactored the app to only contain one Robot singleton object, but the different processes still asynchronously invoke input commands. As far as I can tell, this did not change the behavior of my app. My next step might be to created a synchronized wrapper around the Robot singleton to see if that helps, but given the symptoms, I don't know why it would.
I've had problems using the Robot class before. I forget exactly what I've done, but it has caused the computer to lock up and I've been forced to reboot.
I'm not familiar with the vagaries of Robot, but Uncaught exceptions in GUI applications can produce very odd results as the event dispatch thread dies and restarts. You might get some ideas from How uncaught exceptions are handled.
This can happen if u activated any screen saver or some thing like that, then this robot actions will stop working
i got this problem in the following way
i am having some GUI based applications and i written some test code based on Robot class.
but if i activated screen saver in my system this test cases stopped working...
please check any such scenarios are there in your case
for Ross, I am pretty sure that you have a policy problem which mean that you don't have permission and getting block by win7. To get this permission you must create a policy and that is a big of a story. Check what info you can get from sun website.
For the others if your program stops working after some period of time it might be that you are not handling all of the exception in your program right. Try to get the line when it stops: you can do it by just sending a line of text to the system console, and rewrite it to get the performance you want.
For the rest check your code and check it good very good to see that you are not getting into a dead lock which might stuck your pc if it has something with it.
Also check to see the CPU usage and see if your program is overloading it if it does your CPU temperature control will restart or turn off your PC automatically.
If i didn't hit the problem, let me know; if you solved the case please let me know what you did.
We have two machines with almost exactly same behavior with Java applications.
One is with Windows 7 64 bit, where Eclipse 64bit and Java 6 (64bit) is causing exactly same freeze.
Other is with Windows 7 32 bit and Java application utilizing a lot of CPU and disk activity causing freeze.
Both machines are notebooks from Toshiba with modern CPU's (Core 2 Duo).
Also both machines have NOD32 anti virus installed.
Standard apps (Office, Skype, Firefox,...)
We seem to tracked down problem to NOD32. When we disable NOD32 it seems that beahaviour does not occure anymore.
I want to point out that I don't think it's NOD32 itself, but some combination of Windows 7, Java JDK and NOD32.
I ran into a similar issue on Mac OS X 10.6.7 but it was not freezing entire system but the entire java process where my application was running in, and interesting at random basis. Workaround for this was call:
Toolkit.getDefaultToolkit();
Before create any Robot, in example:
public static void main(String[] args) {
Toolkit.getDefaultToolkit();
//Blah blah
}
Same call is made in init method at Robot class so seems where the problems are coming from, this is stupid and does not make a lot sense to me but works perfectly now :)

Categories