Class Synced<T>

  • Type Parameters:
    T - Type of result
    All Implemented Interfaces:
    Scalar<T>

    public final class Synced<T>
    extends Object
    implements Scalar<T>
    Scalar that is thread-safe.

    This class implements Scalar, which throws a checked Exception. This may not be convenient in many cases. To make it more convenient and get rid of the checked exception you can use the Unchecked decorator. Or you may use IoChecked to wrap it in an IOException.

    
     final List<Integer> list = new LinkedList<>();
     final int threads = 100;
     new RunsInThreads<>(
         new SyncScalar<>(() -> list.add(1)), threads
     ); // list.size() will be equal to threads value
     

    Objects of this class are thread-safe.

    Since:
    0.3
    • Constructor Detail

      • Synced

        public Synced​(Scalar<? extends T> src)
        Ctor.
        Parameters:
        src - The Scalar to cache
      • Synced

        public Synced​(Scalar<? extends T> scalar,
                      Object lock)
        Ctor.
        Parameters:
        scalar - The Scalar to cache
        lock - Sync lock
    • Method Detail

      • value

        public T value()
                throws Exception
        Description copied from interface: Scalar
        Convert it to the value.
        Specified by:
        value in interface Scalar<T>
        Returns:
        The value
        Throws:
        Exception - If fails