Re: Continuously re-spawning a stopped/killed thread

Martin Buchholz via Concurrency-interest <[email protected]> Tue, 15 Dec 2020 12:44:21 -0800
Newsgroups gmane.comp.java.jsr.166-concurrency
Message-ID <CA+kOe0_dS11ZmG8ZFFcUeCe5kV-z0qfB9JfCJUqnanaS6rJO=w@mail.gmail.com>
Why not just try { ... } catch (...) { handle ... } in your thread's main
method?

On Mon, Dec 14, 2020 at 2:27 AM Volkan Yazıcı via Concurrency-interest <
[email protected]> wrote:

> Hello,
>
> In Log4j, we need to run a background task and keep it alive — unless JVM
> is stopped or our *while (!stopped)* condition fails after an interrupt.
> That is, if the task fails for some reason (e.g., by means of throwing an
> exception, interruption, or *ThreadDeath* due to *Thread#stop()*), it
> needs to be re-spawned. What is the most robust/decent way to implement
> this?
>
> For the records, this is the problem I am dealing with in Log4j:
> https://github.com/apache/logging-log4j2/commit/56436ad2176eac000d2821690e4373f097b76670#r44892412
>
> In a nutshell, we have a wrapper running in the background that calls
> Log4j *Layout*s to render *LogEvent*s. Though certain layouts can do
> really strange things from calling *Thread.currentThread().stop()* to
> throwing an *Error*. These cause the wrapper thread to get killed.
>
> I have found work arounds using uncaught exception handlers
> <https://howtodoinjava.com/java/multi-threading/restart-thread-uncaughtexceptionhandler/>,
> though I couldn't be sure if this is the right way to do it.
>
> Kind regards.
> _______________________________________________
> Concurrency-interest mailing list
> [email protected]
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>

_______________________________________________
Concurrency-interest mailing list
[email protected]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest