All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.core.thread.sleeper.CurrentSleeper Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.thread.sleeper;

import com.softicar.platform.common.core.singleton.Singleton;
import com.softicar.platform.common.core.thread.sleep.Sleep;
import java.util.Objects;

/**
 * Provides a {@link ThreadLocal} to define the {@link ISleeper} to use.
 * 

* This class can be used in unit tests to control the behavior of * {@link Sleep#sleep}. * * @author Oliver Richers */ public class CurrentSleeper { private static final Singleton CURRENT_SLEEPER = new Singleton<>(DefaultSleeper::new); /** * Returns the default {@link ISleeper} for the current {@link Thread}. *

* If no {@link ISleeper} has been defined explicitly, an instance of * {@link DefaultSleeper} will be returned. * * @return the current {@link ISleeper} (never null) */ public static ISleeper get() { return CURRENT_SLEEPER.get(); } /** * Defines the {@link ISleeper} to be returned by {@link #get()}. * * @param sleeper * the {@link ISleeper} to use (never null) */ public static void set(ISleeper sleeper) { CURRENT_SLEEPER.set(Objects.requireNonNull(sleeper)); } /** * Resets this to the {@link DefaultSleeper}. */ public static void reset() { CURRENT_SLEEPER.set(null); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy