Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workaround for Slow Java Swing Menus

Tags:

java

swing

menu

In Java 7 and 8 there is a bug in Swing menus that causes it to be slow when running an application remotely over X11 while other X11 applications are running. This issue was introduced in Java 7 and has never been fixed. Does anyone have any suggestions on a workaround. Using nxclient addresses this Swing menu issue, but introduces its own unwelcome issues.

The steps to reproduce the Swing menu issue are: - run any X11 application locally with some activity - log into a remote server using ssh -Y someserver - execute any Java GUI application (e.g. jvisualvm) running Java 7 or 8 - select a menu and observe a several second delay in response

like image 985
Tom Pelaia Avatar asked Sep 23 '14 19:09

Tom Pelaia


2 Answers

Just spent an entire day trying to solve the same issue. There's barely any info out there.

Local machines:

  1. Linux FedoraCore 20, KDE desktop, NVIDIA GeForce 7300 LE
  2. Linux FedoraCore 20, KDE desktop, NVIDIA GeForce GT 720

Running remote Java GUI over ssh, swing popups are extremely slow for PC2. Desktop freezes until popup appears. On the other hand, PC1 runs very fast/smooth, with no problems at all.

Turns out, in my case, the problem is that PC2 has 2 monitors. The closest bug report I could find is: JDK-8004103 : sun.awt.X11.XToolkit.getScreenInsets() may be very slow and it appears to be still open.

Temporary Workarounds:

  1. In KDE, Disable second monitor, Launch Application, Enable second monitor
  2. Work in Gnome Desktop (My Gnome environment not affected by this issue)
  3. Launch remote Java app using Java 6 (Issue not present in Java6)

None of these are ideal workarounds, but considering that my Desktop freezes for 3-4 seconds every time I click on a menu item, they'll do for the time being.

like image 143
AndreasP Avatar answered Oct 27 '22 17:10

AndreasP


I finally found much better workaround for this problem. When opening the SSH connection to the remote computer, set ForwardX11Trusted option to "no".

ssh -o ForwardX11Trusted=no -X [email protected]

For me, opening a ComboBox reduced from ~14s to instantly. Unfortunately, I currently don't have any Java applications with Swing Menu installed on the server, but I think this should work for Menus too.

If you don't want to type that option every time, add the following line to ssh config file (/etc/ssh/ssh_config)

ForwardX11Trusted no
like image 3
MlinarG Avatar answered Oct 27 '22 17:10

MlinarG