DEV Community

loading...

Start-up Logic in Static Initializers

remcobuddelmeijer profile image Remco Buddelmeijer ・1 min read

Start-up Logic in Static Initializers

It might happen, you need something to be done the second the class get loaded in (by the Class Loader).
Especially in large applications this can be quite the struggle. However there are multiple approaches to implement start-up logic in any of your classes.

What is your favorable approach to this?

  • Would it be initialize it once using initializers?
  • Do you prefer using a certain library/framework for this (f.e. @PostConstruct for Spring Beans)?
  • Or do you have a complete other approach to this?

And why?

(Personally I prefer to have one-time start-up logic in static initializers/Bean initializers. And multi-time start-up logic in class constructors)

Discussion (0)

pic
Editor guide