This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.

anjan singh

Greenhorn
+ Follow
since Feb 04, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

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 log4j.properties file add header property to your layout:

Hi

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 log4j.properties 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?
12 years ago