Announcement Announcement Module
Collapse
No announcement yet.
Application is not shutting down when logging is configured using AmqpAppender Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Application is not shutting down when logging is configured using AmqpAppender

    Hi,

    I have a simple Java application which uses log4j with AmqpAppender.
    The log4j configuration :

    Code:
    log4j.rootCategory=INFO, stdout
    
    log4j.logger.in.loggersample.main.MainApplication=INFO, amqp
    
    
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    
    log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
    #log4j.appender.stdout.layout.ConversionPattern=%-5p %8t [%40.40c{4}]: %m%n
    
    log4j.category.in.gov.uidai.main=DEBUG
    
    
    log4j.appender.amqp=org.springframework.amqp.rabbit.log4j.AmqpAppender
    log4j.appender.amqp.layout=org.apache.log4j.PatternLayout
    log4j.appender.amqp.layout.ConversionPattern=%d %p %t [%c] - <%m>
    
    #-------------------------------
    ## Connection settings
    #-------------------------------
    log4j.appender.amqp.host=localhost
    log4j.appender.amqp.port=5672
    log4j.appender.amqp.username=guest
    log4j.appender.amqp.password=guest
    log4j.appender.amqp.virtualHost=/
    #log4j.appender.amqp.connectionTimeout=0 # No setter for connection timeout.
    #-------------------------------
    ## Exchange name and type
    #-------------------------------
    log4j.appender.amqp.exchangeName=app.log4j.log4
    log4j.appender.amqp.exchangeType=fanout
    #-------------------------------
    ## Log4J-format pattern to use to create a routing key.  
    ## The application id is available as %X{applicationId}.
    #-------------------------------
    log4j.appender.amqp.routingKeyPattern=INFO
    #-------------------------------
    ## Whether or not to declare this configured exchange
    #-------------------------------
    log4j.appender.amqp.declareExchange=true
    #-------------------------------
    ## Message properties
    #-------------------------------
    log4j.appender.amqp.contentType=text/plain
    log4j.appender.amqp.contentEncoding=null
    #-------------------------------
    ## Sender configuration
    #-------------------------------
    log4j.appender.amqp.senderPoolSize=2
    log4j.appender.amqp.maxSenderRetries=30
    log4j.appender.amqp.applicationId=log4j-sample-2
    Code:
    package in.loggersample.main;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    public class MainApplication {
    
    	public static Log logger = LogFactory.getLog(MainApplication.class);
    	
    	public static void main(String[] args) {
    		logger.info("Testing Logger");
    		System.out.println("Finished!!!");
    	}
    }
    Am using a fanout exchange,routingKeyPattern=INFO for testing purpose. The problem is that even after the "finished!!!" gets printed on the console. The application is not exiting. i can see 4 threads in the thread dump which are still running.


    Code:
    "pool-2-thread-2" prio=6 tid=0x01c3dc00 nid=0x454 waiting on condition [0x18bef000]
       java.lang.Thread.State: WAITING (parking)
    	at sun.misc.Unsafe.park(Native Method)
    	- parking to wait for  <0x0925d560> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    	at java.util.concurrent.locks.LockSupport.park(Unknown Source)
    	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
    	at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
    	at org.springframework.amqp.rabbit.log4j.AmqpAppender$EventSender.run(AmqpAppender.java:417)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    
       Locked ownable synchronizers:
    	- <0x041d94b8> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
    
    "pool-2-thread-1" prio=6 tid=0x01c3d800 nid=0x1ee8 waiting on condition [0x18b9f000]
       java.lang.Thread.State: WAITING (parking)
    	at sun.misc.Unsafe.park(Native Method)
    	- parking to wait for  <0x0925d560> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    	at java.util.concurrent.locks.LockSupport.park(Unknown Source)
    	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
    	at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
    	at org.springframework.amqp.rabbit.log4j.AmqpAppender$EventSender.run(AmqpAppender.java:417)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    
       Locked ownable synchronizers:
    	- <0x041d9558> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
    
    "AMQP Connection 127.0.0.1:5672" prio=6 tid=0x01c3d000 nid=0x1b80 runnable [0x18b4f000]
       java.lang.Thread.State: RUNNABLE
    	at java.net.SocketInputStream.socketRead0(Native Method)
    	at java.net.SocketInputStream.read(Unknown Source)
    	at java.io.BufferedInputStream.fill(Unknown Source)
    	at java.io.BufferedInputStream.read(Unknown Source)
    	- locked <0x041d2410> (a java.io.BufferedInputStream)
    	at java.io.DataInputStream.readUnsignedByte(Unknown Source)
    	at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
    	at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:131)
    	- locked <0x041d2430> (a java.io.DataInputStream)
    	at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:501)
    
       Locked ownable synchronizers:
    	- None
    
    "log-event-retry-delay" daemon prio=6 tid=0x01c3cc00 nid=0x1a88 in Object.wait() [0x189ff000]
       java.lang.Thread.State: WAITING (on object monitor)
    	at java.lang.Object.wait(Native Method)
    	- waiting on <0x092504e0> (a java.util.TaskQueue)
    	at java.lang.Object.wait(Object.java:485)
    	at java.util.TimerThread.mainLoop(Unknown Source)
    	- locked <0x092504e0> (a java.util.TaskQueue)
    	at java.util.TimerThread.run(Unknown Source)
    
       Locked ownable synchronizers:
    	- None
Working...
X