0

I'm hitting a strange issue when trying to run a swing project from Gradle from within a VM (hypervisor being kvm).

The code runs fine on every attempt from the host OS, yet hangs in the jframe.pack() method most times when run from within the guest. I am assuming the issue is something along the lines of thread synchronization.

As with most swing apps, it is unrealistic to attempt to post the code to show here.... but I can point to it in GitHub

I'm not playing with threads in any huge way otherwise, basically just letting swing manage itself. I'm also giving the guest ample resources and don't have any issues running any other application.

I'm not teribly familiar with the nuances of the threading going on here, what could be the source of the issue? I'm not doing anything fancy in the way of creating my own threads, etc. I am simply setting up my ui as one would "normally", and letting swing handle its own threading.

Host:

  • CentOS 8 stream
  • 8 core/ 32g ram
  • Java 8

Guest:

  • Ubuntu 19.10
  • allocated 8 core/ 16g ram
  • Java 8

A simplified walk through of how the swing app is setup:

class Runner(){
    private Gui gui;

    public runGui(){ //what is run to run the gui
        gui = new Gui();
    }
}

// partially setup with Intellij's form builder
class Gui(){
    private JFrame mainFrame;
    //many other member variables and functions


    public void Gui(){
        //general setup of GUI code. generation of elements, event binding, etc
        this.mainFrame = new JFrame();
        ...

        // pack and open
        this.mainFrame.pack();
        this.mainFrame.setVisible(true);
    }

    {
        //intellij autogenerated form builder. Standard setup code.
        $$$setupUI$$$();
    }
}


Snappawapa
  • 1,697
  • 3
  • 20
  • 42
  • To narrow it down, try one of the complete [examples](https://stackoverflow.com/search?tab=votes&q=%5bswing%5d%20SwingWorker) in the [tag:swing] tag to check your environment; try [this approach](https://stackoverflow.com/q/7787998/230513) to look for violations in your code. – trashgod Jan 16 '20 at 02:40
  • 1800 lines of code is too much to wade through. If you need more help, you will need to create a [**MINIMAL** reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – Stephen C Jan 16 '20 at 03:52
  • I agree it is too much to wade through. Which makes it a challenge to condense. I have updated with a general workflow of how the gui works and is opened. – Snappawapa Jan 16 '20 at 04:28

1 Answers1

1

I'm not terribly familiar with the nuances of the threading going on here, what could be the source of the issue?

Yes. That is probably the source your issues. Thread timing in a VM is likely to be different than in a desktop machine. However, if your code is written correctly, it should not be affected by this.

Without more information (for example a minimal reproducible example), the best we can do is point you at some resources on threading in general, and the correct way to do threading in Swing applications:


The hardware characteristics are unlikely to be relevant to the problem. Certainly, they don't affect what you need to do to write correct code.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks for pointing out good resources. My issue was that I wasn't using `SwingUtilities.invokeLater()` to start my gui (honestly didn't know it was a thing to do or that it existed...). Now hitting other synchronization issues due to how I have it setup, but at least now I know where to start. Thanks! – Snappawapa Jan 16 '20 at 04:35