I am using log4j AsyncAppender
. i wrote my own appender to customise the logger as below.
public class MyAppender extends AppenderSkeleton {
@Override
public void close() {
}
@Override
public boolean requiresLayout() {
return false;
}
@Override
protected void append(LoggingEvent event) {
//Here am doing some logic which will connect database and fetch some records.
}
}
My log4j configuration:
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- Appenders -->
<appender name="stdout" class="com.sample.MyAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c] - %m%n"/>
</layout>
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<param name="BufferSize" value="500"/>
<appender-ref ref="stdout"/>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="ASYNC" />
</root>
</log4j:configuration>
Now everything works fine. Im MyAppender
i will fire a Select
query and fetch some details from the table and send those details using java mail API. As i am using AsyncAppender
, it does not block existing running thread and the MyAppender logic is executed Asynchronously.My question is if the main thread completes its execution before MyAppender
logic gets completed then is there any guarantee that the logic in MyAppender
will be completed even if main thread completes its execution?
Thanks!