Class with datastructure reused by multiple other classes SpringBoot

If you are just looking to start a always on process when app starts ( even better when RuleManager gets initialized ), then you should simply create a new thread in the constructor of RuleManager :

methodCalledByConstructor()
{
 new Thread(()->{
        // loop start
        // access and check the hashmap 
        // do what is necessary
        // sleep for a sometime
        // loop end
    }).start();
 }

But if the work is only required when some event occurs, then use observer pattern for more elegant solution.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top