Repository: jenkinsci/jenkins
File: core/src/main/java/hudson/model/AsyncPeriodicWork.java (Java)

Code before:
    /**
     * Human readable name of the work.
     */
    public final String name;

    private Thread thread;

    private final AtomicBoolean pending = new AtomicBoolean(false);

    protected AsyncPeriodicWork(String name) {
        this.name = name;
        this.logRotateMillis = TimeUnit.MINUTES.toMillis(
                SystemProperties.getLong(getClass().getName() + ".logRotateMinutes", LOG_ROTATE_MINUTES));
        this.logRotateSize = SystemProperties.getLong(getClass().getName() + ".logRotateSize", LOG_ROTATE_SIZE);
    }

    /**
     * Schedules this periodic work now in a new thread, if one isn't already running.
     */
    @Override
    @SuppressWarnings("deprecation") // in this case we really want to use PeriodicWork.logger since it reports the impl class
    public final void doRun() {
        try {
            if (thread != null && thread.isAlive()) {
                if (queueIfAlreadyRunning()) {
                    logger.log(Level.FINE, "Scheduling another run of {0} since it is already running", name);
                    pending.set(true);
                } else {
                    logger.log(this.getSlowLoggingLevel(), "{0} thread is still running. Execution aborted.", name);
                }
                return;
            }
            thread = new Thread(() -> {
                logger.log(Level.FINE, "Started {0}", name);
                long startTime = System.currentTimeMillis();
                long stopTime;

                LazyTaskListener l = new LazyTaskListener(this::createListener, String.format("Started at %tc", new Date(startTime)));
                try {
                    try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) {
                        execute(l);
                    }
                } catch (IOException e) {
                    Functions.printStackTrace(e, l.fatalError(e.getMessage()));
                } catch (InterruptedException e) {
                    Functions.printStackTrace(e, l.fatalError("aborted"));
                } finally {
                    stopTime = System.currentTimeMillis();
                    l.close(String.format("Finished at %tc. %dms", new Date(stopTime), stopTime - startTime));
                }


Review comment (performance):
or
```suggestion
                    logger.log(this.getSlowLoggingLevel(), "Scheduling another run of {0} since it is already running", name);
```
?

Code after:
    /**
     * Human readable name of the work.
     */
    public final String name;

    private Thread thread;

    private final AtomicBoolean pending = new AtomicBoolean(false);

    protected AsyncPeriodicWork(String name) {
        this.name = name;
        this.logRotateMillis = TimeUnit.MINUTES.toMillis(
                SystemProperties.getLong(getClass().getName() + ".logRotateMinutes", LOG_ROTATE_MINUTES));
        this.logRotateSize = SystemProperties.getLong(getClass().getName() + ".logRotateSize", LOG_ROTATE_SIZE);
    }

    /**
     * Schedules this periodic work now in a new thread, if one isn't already running.
     */
    @Override
    @SuppressWarnings("deprecation") // in this case we really want to use PeriodicWork.logger since it reports the impl class
    public final void doRun() {
        try {
            if (thread != null && thread.isAlive()) {
                if (queueIfAlreadyRunning()) {
                    logger.log(this.getSlowLoggingLevel(), "Scheduling another run of {0} since it is already running", name);
                    pending.set(true);
                } else {
                    logger.log(this.getSlowLoggingLevel(), "{0} thread is still running. Execution aborted.", name);
                }
                return;
            }
            thread = new Thread(() -> {
                logger.log(Level.FINE, "Started {0}", name);
                long startTime = System.currentTimeMillis();
                long stopTime;

                LazyTaskListener l = new LazyTaskListener(this::createListener, String.format("Started at %tc", new Date(startTime)));
                try {
                    try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) {
                        execute(l);
                    }
                } catch (IOException e) {
                    Functions.printStackTrace(e, l.fatalError(e.getMessage()));
                } catch (InterruptedException e) {
                    Functions.printStackTrace(e, l.fatalError("aborted"));
                } finally {
                    stopTime = System.currentTimeMillis();
                    l.close(String.format("Finished at %tc. %dms", new Date(stopTime), stopTime - startTime));
                }