I wrote a server that receives RMI requests and performs some operations.
An instance of Log4J Logger is created for each request. The following is a snippet of code that is used to create an instance of Logger.
Logger log = Logger.getLogger("log_" + requestID); log.setAdditivity(false); FileAppender appender = null; try { PatternLayout layout = new PatternLayout("%-5p %C{1} %d{yyyy-MM-dd HH:mm:ss} : %m%n"); appender = new FileAppender(layout, logFileName, false); } catch(Exception e) { logger.error("Error initializing logger", e); } log.addAppender(appender); log.setLevel(level);
Everything is fine here. The problem is overtime after receiving a large number of requests, the number of open files for this server process increases and does not decrease, which leads to the failure of the process using the Exception expression Too many open files .
After further verification, it was discovered that the problem is that the file descriptors are not freed after the request is completed. I tried to look at the Log4J documentation, but could not find anything about how to close only one log without affecting the others that can run on different threads.
Any ideas here?
source share