Right now in my application, at certain points, we are logging some heavy stuff into the log files.
Basically only for logging, we are creating JSON of the data available and then logging into Log files. This is a business requirement to log data in JSON format.
Now creating JSON from the data available and then logging to FILE takes a lot of time and impacts the original request return time. Now idea is to improve the situation.
One of the things that we have discussed is creating a thread pool using
Executors.newSingleThreadExecutor()
in our code and then submitting the task to it which does the conversion of data into JSON and subsequent logging.
Is it a good approach to do this? As we are managing the thread pool itself, is it going to create some issues?
I would appreciate it if someone can share better solutions. Someway to use Log4j for this. I tried to use AsyncAppender but didn't achieve any desired result.
We are using EJB 3, JBoss 5.0, Log4j, and Java6.