For better logging (especially in cases of the LogService implemented using
a log framework which allows including the thread name in log messages) the
thread name is set to include the task to run.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@809601 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/UpdateThread.java b/configadmin/src/main/java/org/apache/felix/cm/impl/UpdateThread.java
index 8fc65f6..ffe80b9 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/UpdateThread.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/UpdateThread.java
@@ -1,4 +1,4 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -31,17 +31,21 @@
 public class UpdateThread extends Thread
 {
 
+    // the base name of the thread which is set while there is no
+    // task to run
+    private static final String BASE_THREAD_NAME = "Configuration Updater";
+
     // the configuration manager on whose behalf this thread is started
     // (this is mainly used for logging)
     private ConfigurationManager configurationManager;
-    
+
     // the queue of Runnable instances  to be run
     private LinkedList updateTasks;
 
 
     public UpdateThread( ConfigurationManager configurationManager )
     {
-        super( "Configuration Updater" );
+        super( BASE_THREAD_NAME );
 
         this.configurationManager = configurationManager;
         this.updateTasks = new LinkedList();
@@ -84,6 +88,9 @@
             // otherwise execute the task, log any issues
             try
             {
+                // set the thread name indicating the current task
+                setName( BASE_THREAD_NAME + " (" + task + ")" );
+
                 configurationManager.log( LogService.LOG_DEBUG, "Running task " + task, null );
                 task.run();
             }
@@ -91,6 +98,11 @@
             {
                 configurationManager.log( LogService.LOG_ERROR, "Unexpected problem executing task", t );
             }
+            finally
+            {
+                // reset the thread name to "idle"
+                setName( BASE_THREAD_NAME );
+            }
         }
     }
 
@@ -112,7 +124,7 @@
 
             // append to the task queue
             updateTasks.add( update );
-            
+
             // notify the waiting thread
             updateTasks.notifyAll();
         }