Class TransactionAwareSingleton<T>

  • All Implemented Interfaces:
    TransactionListener, org.alfresco.util.transaction.TransactionListener

    public class TransactionAwareSingleton<T>
    extends TransactionListenerAdapter
    A transactionally-safe storage class for singleton objects. Changes to the singleton are only visibly promoted when the transaction is committed.

    private static final TransactionAwareSingleton MY_SINGLETON = new TransactionAwareSingleton();

    All modifications to the singleton via get() and put(Object) are made in a transaction-local manner and promoted to the shared value in a thread-safe manner upon transacton completion. Transaction-local changes take precedence over the shared value.

    Author:
    Derek Hulley
    See Also:
    AlfrescoTransactionSupport
    • Constructor Detail

      • TransactionAwareSingleton

        public TransactionAwareSingleton()
    • Method Detail

      • get

        public T get()
        Returns:
        Returns the transaction- and thread-safe wrapped instance
      • put

        public void put​(T value)
        Store the value in a transaction- and thread-safe manner. It will only be persisted at the end of the transaction but will be visible to the current transaction from this call onwards.
        Parameters:
        value - the value to store