Is it possible to decrease the startup time of my application?

Asked

Viewed 76 times

1

I’ve seen a lot here and at Stackoverflow in English about Swing and Runnable, I still couldn’t solve my problem.

I am developing a work for the college (interdisciplinary work involving Distributed Systems/Advanced Data Structures/Technology and Education), which consists of a Crossword game. The problem is that the user will have the possibility to "mount" the Crossword.

That is, from a secondary window, it will tell you how many rows and columns the Crossword will have. The minimum amount will be 10 rows per 10 columns. As you may have already guessed, when closing the form and calling the method that builds the interface (matrix JTextField) in the main window, there is an approximate time of 8 seconds until the window "thaws". And the time gets longer as the "grid" also grows. As a parameter: For the construction of a 15 x 15 grid, the matrix appears in approximately 1 second. However, it takes 18 seconds to "defrost".

Is there a solution to this problem?

1 answer

2

Use the EDT.

The Event dispatching thread (EDT) is a Java thread for processing Abstract Window Toolkit (AWT) events, it queues events coming from the interface to handle in parallel. It is a classic example of the concept of event-oriented programming, which is popular in many other contexts, for example web browsers or web servers.

It implements the worker design Pattern to do this parallel processing of the interface and thus manage to handle multiple tasks.

public void actionPerformed(ActionEvent e)
{
  new Thread(new Runnable()
  {
    final String text = readHugeFile();
    SwingUtilities.invokeLater(new Runnable() 
    {
      public void run()
      {
        textArea.setText(text);
      }
    });
  }).start();
}

See the example, it uses the class SwingUtilities that invokes a new thread to set the text. That kind of approach may be the solution to your problem.

  • Thanks for trying to help user34038. I had already tried the way you put and unfortunately did not improve the performance. Even so I thank you. Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.