1

Just recently I went back to a project I had not worked on in a while. The first time I ran it during this new programming session, it took over three minutes to load. I have no idea what could have changed between now and the last time I worked on it (about three months ago) but I know the code had not changed.

I tracked the problem down to the JFrame constructor. I found this post:

First call to JFrame constructor takes a long time during Swing application startup (because of java.awt.Window())

However it does seem relevant as his problem only took a few hundred milliseconds. I did use his code for a simple test and my output was as follows:

202720 for first JFrame.
0 for second JFrame.

I am using jdk-7u7-windows-x64. I have absolutely no idea what could be causing this so any assistance would be appreciated.

Thank you.

EDIT Here is the code that I copied from the linked post:

import javax.swing.*;
public class Main {
public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            long start;

            start = System.currentTimeMillis();
            JFrame frame1 = new JFrame("Frame1");
            System.out.println((System.currentTimeMillis() - start) + " for first JFrame.");

            start = System.currentTimeMillis();
            JFrame frame2 = new JFrame("Frame2");
            System.out.println((System.currentTimeMillis() - start) + " for second JFrame.");

            frame1.setVisible(true);
            frame2.setVisible(true);
        }
    });     
}
}

EDIT I have done all of the usual guess work

+ Restarted Eclipse
+ Restarted Windows
+ Re-installed Java
+ Exported to a Jar (same result)
Community
  • 1
  • 1
portigui
  • 53
  • 2
  • 7
  • 5
    Could you share the code in which you create this JFrame? – Jeroen Baert Nov 15 '12 at 22:51
  • Sounds like you have some blocking process/long running loop which is running when you create the frames – MadProgrammer Nov 15 '12 at 22:58
  • For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Nov 16 '12 at 02:23
  • Andrew, the code I pasted is Short, Self Contained, Correct (Compilable), Example. It is the test program I have been using trying to diagnose the problem. It is short, it is all you need, it shows the problem and it compiles. I am not sure what else you would need. If there is something else, please let me know and I will provide it. – portigui Nov 16 '12 at 03:30
  • Copy/paste that exact 'code snippet' into an IDE, compile it as-is. It will not compile and is therefore not self-contained! When I do that experiment I see 12 compilation errors, the first of which is `I:\projects\..\SillySnippet.java:1: class, interface, or enum expected public static void main(String[] args) {`. – Andrew Thompson Nov 16 '12 at 03:45
  • Or to put that another way, it needs to be a properly formed class, with imports, to be an SSCCE. – Andrew Thompson Nov 16 '12 at 03:46
  • My apologies, I did not include the import statement. Here it is with that line of code added. – portigui Nov 16 '12 at 03:49

0 Answers0