Package org.eclipse.net4j.util.concurrent

# Interface CriticalSection

All Known Implementing Classes:
  `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;
     });

Since:
  3.29
Author:
  Eike Stepper

## Nested Class Summary

Nested Classes
Modifier and Type
Interface
Description
`static class`
`CriticalSection.LockedCriticalSection`
A `CriticalSection` implementation that uses a given `Lock` to synchronize access to the critical section.
`static class`
`CriticalSection.SynchronizedCriticalSection`
A `CriticalSection` implementation that uses a given mutex object to synchronize access to the critical section.
`static class`
`CriticalSection.UnsynchronizedCriticalSection`
A `CriticalSection` implementation that does not perform any synchronization.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final CriticalSection`
`UNSYNCHRONIZED`

## Method Summary

Modifier and Type
Method
Description
`default <V, E extends Throwable>
V`
`call(Class<E> exceptionType, Callable<V> callable)`
`<V> V`
`call(Callable<V> callable)`
`Condition`
`newCondition()`
`default void`
`run(Runnable runnable)`
`default boolean`
`supply(BooleanSupplier supplier)`
`default double`
`supply(DoubleSupplier supplier)`
`default int`
`supply(IntSupplier supplier)`
`default long`
`supply(LongSupplier supplier)`
`default <V> V`
`supply(Supplier<V> supplier)`

## Field Details

### UNSYNCHRONIZED

static final CriticalSection UNSYNCHRONIZED

## Method Details

### run

default void run(Runnable runnable)

### supply

default <V> V supply(Supplier<V> supplier)

### supply

default boolean supply(BooleanSupplier supplier)

### supply

default int supply(IntSupplier supplier)

### supply

default long supply(LongSupplier supplier)

### supply

default double supply(DoubleSupplier supplier)

### call

default <V, E extends Throwable> V call(Class<E> exceptionType, Callable<V> callable) throws E

Throws:
  `E`

### call

<V> V call(Callable<V> callable) throws Exception

Throws:
  `Exception`

### newCondition

Condition newCondition()