Module bus.http

Class NamedRunnable

java.lang.Object
org.miaixz.bus.http.metric.NamedRunnable
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
RealCall.AsyncCall

public abstract class NamedRunnable extends Object implements Runnable
An abstract Runnable implementation that always sets its thread name.
Since:
Java 17+
Author:
Kimi Liu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
    The name of the runnable, which will be set as the thread name.
  • Constructor Summary

    Constructors
    Constructor
    Description
    NamedRunnable(String format, Object... args)
    Constructs a new NamedRunnable with a formatted name.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    The abstract method to be implemented by subclasses, containing the actual logic to be executed.
    final void
    run()
    Executes the runnable, setting the thread name before execution and restoring it afterwards.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • name

      protected final String name
      The name of the runnable, which will be set as the thread name.
  • Constructor Details

    • NamedRunnable

      public NamedRunnable(String format, Object... args)
      Constructs a new NamedRunnable with a formatted name.
      Parameters:
      format - The format string for the name.
      args - The arguments for the format string.
  • Method Details

    • run

      public final void run()
      Executes the runnable, setting the thread name before execution and restoring it afterwards.
      Specified by:
      run in interface Runnable
    • execute

      protected abstract void execute()
      The abstract method to be implemented by subclasses, containing the actual logic to be executed.