This is an automated email from the ASF dual-hosted git repository. swebb2066 pushed a commit to branch restart_periodic_task_thread in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit e20ff628c1449157634c213446ce5179eecea746 Author: Stephen Webb <[email protected]> AuthorDate: Tue Mar 24 12:23:09 2026 +1100 Watch for configuration files changes after LogManager::shutdown --- src/main/cpp/threadutility.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/cpp/threadutility.cpp b/src/main/cpp/threadutility.cpp index b9dec099..70476af5 100644 --- a/src/main/cpp/threadutility.cpp +++ b/src/main/cpp/threadutility.cpp @@ -82,6 +82,7 @@ struct ThreadUtility::priv_data bool terminated{ false }; int retryCount{ 2 }; Period maxDelay{ 0 }; + bool threadIsActive{ false }; void doPeriodicTasks(); @@ -270,9 +271,15 @@ void ThreadUtility::addPeriodicTask(const LogString& name, std::function<void()> m_priv->maxDelay = delay; auto currentTime = std::chrono::system_clock::now(); m_priv->jobs.push_back( priv_data::NamedPeriodicFunction{name, delay, currentTime + delay, f, 0, false} ); + + // Restart thread if it has stopped. + if (!m_priv->threadIsActive && m_priv->thread.joinable()) + m_priv->thread.join(); + if (!m_priv->thread.joinable()) { m_priv->terminated = false; + m_priv->threadIsActive = true; m_priv->thread = createThread(LOG4CXX_STR("log4cxx"), std::bind(&priv_data::doPeriodicTasks, m_priv.get())); } else @@ -399,6 +406,7 @@ void ThreadUtility::priv_data::doPeriodicTasks() std::unique_lock<std::mutex> lock(this->interrupt_mutex); this->interrupt.wait_until(lock, nextOperationTime); } + this->threadIsActive = false; } } //namespace helpers
