2

I have a JavaFX 8 app that is occasionally hanging/freezing. I feel I've ruled out many causes of the problem, but it's still happening.

Unfortunately I cannot reproduce the freeze/hang on demand. It actually only happens (so far) on my colleague's computer. It can happen not long after the App has been running, or it may happen after many hours, or it may not happen at all. It does not happen after any user initiated event (such as pressing a button).

I have a few background threads running that read data from sockets and update the JavaFX UI. These updates are always done via the Platform.runLater() method.

The background threads may read many hundreds of data updates per second, so I have applied throttling to prevent too many updates on the UI, as suggested here: Throttling javafx gui updates

The user can initiate some long(ish) tasks, which are run on the JavaFX UI thread, or using the Task method. I know and expect the JavaFX UI to block/freeze when calling a method with long execution time on the JavaFX UI thread. But such calls are only made by the user pressing a button and as stated above, the freeze occurs without the user interacting the the App in any way.

I have caught the freezing (twice) on my colleagues computer and inspected the process in JConsole and VisualVM. The thread dump showed no deadlocks. When I compare the thread dump with a non-frozen JavaFX App thread dump, there are no obvious differences.

It appears that only the JavaFX UI is frozen. The background threads continue without error.

The CPU is not high and the computer is not running slow when the freeze occurs.

My App code consists of many classes, so it's not straight forward to include it here, especially as I don't know which method causes to freeze. And therefore my question is rather broader than I would like:

  1. Given the assertions above, do you have any suggestions as to what might be a cause of such an error?
  2. Given the assertions above, do you have any suggestions as to what might be another way to trace such an error?
Community
  • 1
  • 1
Amy
  • 21
  • 3
  • Probably not a very handy tip, but if everything else fails (and it looks like you tried quite a few good options), log **everything** the app is doing. You may then be able to infer the area causing the UI freeze by checking timestamps, or a missed stack trace. – Mena Mar 22 '17 at 14:59
  • Freezing issues like this could also be hardware related, does it occur on multiple machines? Any commonalities between those? JavaFX uses hardware accelerated graphics and if something goes wrong there a freeze of only the UI sounds plausible. – john16384 Mar 22 '17 at 15:05
  • It might be helpfull to add the system information on which you observe this behavior. – mipa Mar 22 '17 at 15:05
  • As John has pointed out this may be a graphics hardware/driver issue. It may thus be helpfull to try the option -Dprism.order=sw in combination with -Dprism.verbose=true in order to see whether the problem still persists. – mipa Mar 22 '17 at 15:18
  • Hi Mipa - thanks. I've actually just stumbled upon that myself and I'm going to try it now. I will be back with an update. – Amy Mar 22 '17 at 15:22

2 Answers2

0

Thanks to John16384 and Mipa for their replies...

I use the javafx-maven-plugin Maven plugin, so the JavaVM arguments by including:

<jvmArgs>
    <jvmArg>-Dprism.verbose=true</jvmArg>
    <jvmArg>-Dprism.order=sw</jvmArg>
</jvmArgs>

in my plugin configuration. Since including this, we haven't had the freeze for a couple of days. I'm hoping this is the final fix!

Amy
  • 21
  • 3
-1

Have you tried AOP ?

Aspect Orientated programming

It in your case would allow you to run a method before and after every method you use, if you logged something if these times were greater than a certain time, then you could determine which bit of code was causing it e.g. log if the time inside a method is greater than 5 seconds

See here for a tutorial to just that

Lomas
  • 34
  • 4