Init system

S

ShadowMan

Hi all
my webapp needs to initialize a lot of classes during the startup.
At moment all these classes implement Initializable interface and are
invoked though the reflection (I have an external configuration file).
A lot of these classes are Singleton/Factory that have a _static_ init()
method, so I need an InitializerClass for each of them, wich simply invokes
the init() method of the class to be initialized!
Are you seeing a more _elegant_ way to "startup" my system?!
Regards that not all classes to be initialized have static init() method...
 
V

Vincent van Beveren

It sounds like the way I would do things.

There are packages that instantiate objects from XML, (though I can't
find it anymore), or through JavaScript (Rhino for example), but that
would be somewhat of an overkill maybe. Its handy though, cause you can
script your initialization that way.

Good luck,
Vincent
 
M

Marcin Grunwald

ShadowMan said:
Hi all
my webapp needs to initialize a lot of classes during the startup.
At moment all these classes implement Initializable interface and are
invoked though the reflection (I have an external configuration file).
A lot of these classes are Singleton/Factory that have a _static_ init()
method, so I need an InitializerClass for each of them, wich simply
invokes the init() method of the class to be initialized!
Are you seeing a more _elegant_ way to "startup" my system?!
Regards that not all classes to be initialized have static init()
method...

Try something like this:
public class Example {
private static boolean initialized = false;
static {
Example.initialized = true;
}
public static void main(String argv[]) {
System.out.println("Initialized: "+Example.initialized);
}
}

It will print:
Initialized: true


That block of code is called during initializing class.
static {
initialized = true;
}

There is one difference between that and your solution:
Class is initialized at the first access to it, not during the startup. But
I think it doesn't mater in your case.
 
S

ShadowMan

Marcin Grunwald said:
ShadowMan wrote:
That block of code is called during initializing class.
static {
initialized = true;
}

There is one difference between that and your solution:
Class is initialized at the first access to it, not during the startup. But
I think it doesn't mater in your case.
It is not so right...
The "init" keep external info (from Properties object, for example) ...
using static block I can make only new instances, set internal variables or
access external resources like Singleton..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top