I Have a Singleton class called FILELOGGER and property called number_of_lines.
I will make sure only one object is able to create for FILELOGGER class which makes singleton.
Throughout my application, my object is able to write it to a file and update number_of_lines property for each write.
What if i use this design pattern in multi threaded environment. How it behaves and i feel like number_of_lines property should be locked when other threads are trying to update. And I might to loose logging of data with delay and performance will be loosing.
Say for example thread T1 is logging at time 10:10:10 and T2 is also logging at the same exact time and both trying to update number_of_lines property.
How to solve this problem? Is there any alternative design pattern to solve this. Thanks for your time.
writeToFilefunction (or your file will be messed up) and the fieldnumber_of_linesto make value atomic.