I have created a multi-threaded java application and the classes are like this,
public class Logic {
public void method1() {
log.info("Inside method 1");
}
public void method2() {
log.info("Inside method 2");
}
...
.... //and so on
}
The input to the class will be a file and each file will be picked up by a single thread.
Now, say I have 5 input files and from the main() when I invoke the Logic class, I have 5 threads running concurrently in the Logic class and updating the same Log file.
I want to log the information of each input file separately.
Like this,
12-04-2013 com.example.Logic: Inside method 1
12-04-2013 com.example.Logic: Inside method 2
12-04-2013 com.example.Logic: Inside method 1
12-04-2013 com.example.Logic: Inside method 2
12-04-2013 com.example.Logic: Inside method 1
12-04-2013 com.example.Logic: Inside method 2
Whereas now it is liek this,
12-04-2013 com.example.Logic: Inside method 1
12-04-2013 com.example.Logic: Inside method 1
12-04-2013 com.example.Logic: Inside method 1
12-04-2013 com.example.Logic: Inside method 2
12-04-2013 com.example.Logic: Inside method 2
12-04-2013 com.example.Logic: Inside method 2
12-04-2013 com.example.Logic: Inside method 3
12-04-2013 com.example.Logic: Inside method 3
12-04-2013 com.example.Logic: Inside method 3
To summarize, I need the logging to be sequential but the processing to be concurrent.
I dont want to try a StringBuffer to save all the values and log it finally or use a seperate log file or reduce the thread count to one.
Thanks in advance!!!!