how to cache mysql query results?

My program fills combo boxes from database and it's kinf of slow

I want my window to open in split second but it takes like 1-2 seconds.

So I'm thinking maby I should get all necessery variables loaded before I open any windows?

Because I have 5 windows and more in future then where should I save my data so that all windows have acces to it?

What would you do to make this app as fast as it can go?

[433 byte] By [hkirsmana] at [2007-11-27 2:11:45]
# 1
You can remove database access from the EDT (event dispatch thread): http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html
DrLaszloJamfa at 2007-7-12 2:05:18 > top of Java-index,Java Essentials,New To Java...
# 2

> You can remove database access from the EDT (event

> dispatch thread):

>

> http://java.sun.com/docs/books/tutorial/uiswing/concur

> rency/index.html

I red it briefly but don't undrestand it very well.

This is what I thought I could do to make my program faster. I need your opinion.

A PreLoad class that gets all necesseray data loaded in the beginning. When I open a new window I pass it on like this:

My Window = w new MyWindow(PreLoad instance initialized somewhere before this line);

Maby I even load a full window into PreLoad instance and make copy of it every time I need to initialize a new window?

But maby I just have to read EDT again?

hkirsmana at 2007-7-12 2:05:18 > top of Java-index,Java Essentials,New To Java...
# 3
I'll ask better question.How would you initialize a window so that it appears in zero time?
hkirsmana at 2007-7-12 2:05:18 > top of Java-index,Java Essentials,New To Java...
# 4

> How would you initialize a window so that it appears in zero time?

JFrame f = new JFrame(title);

... compose f ...

f.pack();

//f is now ready to be made visible.

When you need to see f:

f.setVisible(true);

DrLaszloJamfa at 2007-7-12 2:05:18 > top of Java-index,Java Essentials,New To Java...
# 5

> > How would you initialize a window so that it

> appears in zero time?

>

> > JFrame f = new JFrame(title);

> ... compose f ...

> f.pack();

> //f is now ready to be made visible.

>

> When you need to see f:

> > f.setVisible(true);

>

Sounds like a plan - Load all Windows during program boot or in background (not really sure yet how to do the last 1. goin' to read about even threads again)

But when I close a window, I dispose it and need to open it again. I try to initialize new window during close?

Hm... or maby do reset() function that just resets fields and hides again?

And another question. This is wrong:

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

MainWindow w1 = new MainWindow();

w1.setVisible(true);

}

});

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

MainWindow w2 = new MainWindow();

w2.setVisible();

}

});

Compiles but does not open 2 windows.

hkirsmana at 2007-7-12 2:05:18 > top of Java-index,Java Essentials,New To Java...
# 6
> Compiles but does not open 2 windows.Post a short (< 1 page) example program that demonstrates your problem.
DrLaszloJamfa at 2007-7-12 2:05:18 > top of Java-index,Java Essentials,New To Java...
# 7

/*

* Init.java

*

* Created on April 25, 2007, 3:08 AM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

package Kernel;

import GUI.*;

/**

*

* @author hannes

*/

public class Init {

/** Creates a new instance of Init */

public Init() {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

MainWindow w1 = new MainWindow();

w1.setVisible(true);

}

});

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

MainWindow w2 = new MainWindow();

w2.setVisible(true);

}

});

}

public static void main(String[] args) {

// TODO code application logic here

}

}

hkirsmana at 2007-7-12 2:05:18 > top of Java-index,Java Essentials,New To Java...
# 8

I tried compiling your code, but I get these errors:

...\Init.java:7: cannot find symbol

symbol: class MainWindow

MainWindow w1 = new MainWindow();

^

...\Init.java:7: cannot find symbol

symbol: class MainWindow

MainWindow w1 = new MainWindow();

^

...\Init.java:14: cannot find symbol

symbol: class MainWindow

MainWindow w2 = new MainWindow();

^

...\Init.java:14: cannot find symbol

symbol: class MainWindow

MainWindow w2 = new MainWindow();

^

4 errors

DrLaszloJamfa at 2007-7-12 2:05:19 > top of Java-index,Java Essentials,New To Java...
# 9
well yeah. i didn't include MainWindow class because it contains netbeans ide specific codeyou have netbeans ide?MainWinow is just a empty window. I guess I can write a simple version if u don't have netbeans
hkirsmana at 2007-7-12 2:05:19 > top of Java-index,Java Essentials,New To Java...
# 10

> MainWinow is just a empty window. I guess I can write

> a simple version if u don't have netbeans

This may amaze you, but I am able to write code without an IDE :-) For example:

import javax.swing.*;

class MainWindow extends JFrame {

public MainWindow() {

setSize(100,100);

}

}

public class Init {

public Init() {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

MainWindow w1 = new MainWindow();

w1.setVisible(true);

}

});

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

MainWindow w2 = new MainWindow();

w2.setVisible(true);

}

});

}

public static void main(String[] args) {

new Init();

}

}

I gave the windows size 100x100 so that they are easier to spot. If you see only one, it's because they are stacked.

DrLaszloJamfa at 2007-7-12 2:05:19 > top of Java-index,Java Essentials,New To Java...
# 11
but u call Init twice...
hkirsmana at 2007-7-12 2:05:19 > top of Java-index,Java Essentials,New To Java...
# 12
> but u call Init twice...I call new Init() once.
DrLaszloJamfa at 2007-7-12 2:05:19 > top of Java-index,Java Essentials,New To Java...
# 13
my bad. only main is initialized
hkirsmana at 2007-7-12 2:05:19 > top of Java-index,Java Essentials,New To Java...
# 14
yay. it does work!such a ****. I compiled the wrong project.DrLaszloJamf, you programm GUIs by hand?I can't. For best result I need be able to move things around and see the results asap.NetBeans rules :-)
hkirsmana at 2007-7-12 2:05:19 > top of Java-index,Java Essentials,New To Java...
# 15
**** = d ork
hkirsmana at 2007-7-21 20:20:44 > top of Java-index,Java Essentials,New To Java...