Search code examples
javamultithreadingpojo

Java pattern to access attributes from many classes/threads


I intend to parse a config file. This will happen once at the startup of my application. During it's execution the application has several threads. Each thread needs some of the parsed config parameters (but doesn't need to change them).

how can I do this with plain Java - economical of resources? Thanks a lot!


Solution

  • Create the class that parses the config file as a singleton.

    Parse the config before you start the other threads

    Get the code in the threads to refer to the singleton object containing the parsed config.