Controlling the order of PicoContainer startup

Posted by Trejkaz on Stack Overflow See other posts from Stack Overflow or by Trejkaz
Published on 2010-04-13T05:40:46Z Indexed on 2010/04/13 5:42 UTC
Read the original article Hit count: 314

Filed under:
|
|
|

I have been tasked with doing some refactoring work on how we start up applications. Basically we have a bunch of console apps which were depending on the GUI application startup code, causing bogus dependencies which have kick-on effects for which libraries we need to ship, and which dependencies other modules need to declare.

So I have written a simple startup framework where I basically just throw a bunch of Runnable objects into a list and then run them in order - and it works.

But I was thinking - we already have PicoContainer in our project, so all these things that need to be run on startup could potentially be thrown into a PicoContainer, and if they implement Startable they will start...

But in some cases we want to specify the ordering between them. For example, I don't want any other component writing to the log before we write a header into the log indicating that the application is starting up. I know I can introduce ordering by introducing injection dependencies, but this feels like a hack in this case - I would need to add the log header writer as a dependency for every other component which might write to the log, which isn't great at all.

Nonetheless it seems like it would be nice to control the order of PicoContainer startup, so is there perhaps some other way?

Alternatively I could just keep it simple and stick to my list of Runnable. It does, after all, work.

© Stack Overflow or respective owner

Related posts about java

Related posts about picocontainer