Schnittstelle CriticalSection
- Alle bekannten Implementierungsklassen:
CriticalSection.LockedCriticalSection,CriticalSection.SynchronizedCriticalSection,CriticalSection.UnsynchronizedCriticalSection
public interface CriticalSection
A critical section is a block of code that must be executed by only one thread at a time. This interface provides methods
to run code blocks or callables within such a critical section. Implementations of this interface are expected to
provide the necessary synchronization mechanisms to ensure thread safety.
Example usage:
CriticalSection criticalSection = ...; // Obtain an implementation
criticalSection.run(() -> {
// Code to be executed in the critical section
});
int result = criticalSection.supply(() -> {
// Code that returns a value
return 42;
});
boolean flag = criticalSection.supply(() -> {
// Code that returns a boolean
return true;
});
double value = criticalSection.supply(() -> {
// Code that returns a double
return 3.14;
});
long count = criticalSection.supply(() -> {
// Code that returns a long
return 100L;
});
- Seit:
- 3.29
- Autor:
- Eike Stepper
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypSchnittstelleBeschreibungstatic classACriticalSectionimplementation that uses a givenLockto synchronize access to the critical section.static classACriticalSectionimplementation that uses a given mutex object to synchronize access to the critical section.static classACriticalSectionimplementation that does not perform any synchronization. -
Feldübersicht
Felder -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungdefault <V,E extends Throwable>
V<V> Vdefault voiddefault booleansupply(BooleanSupplier supplier) default doublesupply(DoubleSupplier supplier) default intsupply(IntSupplier supplier) default longsupply(LongSupplier supplier) default <V> V