0

I am trying a java desktop application(I am a student).

It have to deal with four kinds data during start up:

1)project tree(like eclipse Project tree) view data.

Currently I using XMLEncoder/XMLDecoder to save and reload from XML file.

2)user preferences data. such as font,recently files and so on.

Currently I using java.util.prefs.Preferences.

3)Class data .Some factory class like MenuFactory,util class like DatabaseUtil,FileUtil and so on they have some static data.

Currently I using static initializer in these class to initialize default data.

4)Database-related information,such as connection configuration,frequently used database name and table names.

Currently I using java.util.Properties;

What I want to improve:

1) Is it the right way to save my application data in those four kinds mentioned above ?

2)since there are so many data to load,what should I do during a splash screen.

To load them at start up time or delayed to the time when using them ?

At least,I do not want to deceive user by using the following code(not updating progress bar at a meaningful time):

SwingWorker<Void, Integer> worker = new SwingWorker<Void, Integer>() {

            @Override
            protected Void doInBackground() throws Exception {

                for (int i = 0; i < 50; i++) {
                    Thread.sleep(100);// Simulate loading
                    publish(i*2);// Notify progress
                }
                return null;
            }

3) I think too many static initializer may slowdown the program start up ,any suggestion?

wangdq
  • 1,874
  • 17
  • 26
  • 1
    Not sure what you mean by deceive the user, but why not just do what most programs do and have the splash screen have a `JProgressBar` showing the progress of the iniialization, and once everything is complete, make the program screen visible. – Paul Samsotha Jan 06 '14 at 03:44
  • Thanks,you mean just load the data in doInBackground at once and ignore SwingWorker [ process(List chunks)] ? But in this way,progress bar is Redundant, can we make something like eclipse,load data and notify the progress bar at a meaningful time? – wangdq Jan 06 '14 at 03:51
  • Absolutely you can. Update the progress accordingly – Paul Samsotha Jan 06 '14 at 03:52
  • Thanks again,what really puzzled me is, if we want to notify the progress bar at a meaningful time, we have to use a job list pass to the SwingWorker process method,but each job are not the same,should I use function pointer for each job ? or any other way? – wangdq Jan 06 '14 at 04:03
  • You could take look at [this](http://stackoverflow.com/questions/14802662/splash-screen-progress-bar-not-drawing/14803941#14803941) example – MadProgrammer Jan 06 '14 at 04:10
  • I'm not _exactly_ sure the proper way to update, or if there's any way to calculate different progress times of each task to update the bar smoothly time wise during each transaction, but what you can do is guesstimate each percentage of time each process will take, and update the bar accordingly percentage wise after each process. In each process you wouldn't have the effect of the bar increasing, but after each process is finished, you would get a clump increase in the bar. – Paul Samsotha Jan 06 '14 at 04:10

1 Answers1

1

If your app is targeted for high end devices then you can certainly load most of it during the startup/splash screen.

But the issue comes when you have low end devices as well as your target devices. For some of the low end devices loading too much data at startup leaves very less memory for other processing. Some imd leading to even crashing.

Thus it a decision which you have to take wisely and if it some small data then better leave for loading as per required or while that screen is loaded.

Neeraj Jaiswal
  • 216
  • 1
  • 4