Win a copy of Microservices Testing (Live Project) this week in the Spring forum!

anjan singh

+ Follow
since Feb 04, 2012
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by anjan singh

I figured it out.

it was very simple. Find below the code.

Just adding a setter for header does the trick.

And in file add header property to your layout:


How can I read the header text dynamically rather than hardcoding it in the "MyPatternLayout " class itself.

The situation is somewhat like this:
I have 50 files on which i need headers. Each file will have unique header.

How can I get this done by just writing one "MyPatternLayout " class and passing it the header text as an argument. Most preferably the header text could be done from itself.

Any ideas would be greatly appreciated...
here is my problem--

I have 4 classes - Starter , Database and Scheduler and a Test class.

Test class will create a new instance of Starter (which loads and starts the entire process). Starter initializes Scheduler and Database classes.

Test class passes a data to Starter. Starter stores it in a HashMap in Database class. Scheduler reads the same HashMap from Database class.

Now to ensure that the exact same HashMap is access by all classes throughout my java project, I have 2 options-- to make HashMap static or to make Database a singleton class. I have made Database a singleton class for now.

The problem-- if Test class does this

Starter starterInstance1 = new Starter();

Starter starterInstance2 = new Starter();

how do i ensure starterInstance1 and starterInstance2 have their own instance of Database class or the HashMap?
10 years ago