• API

    Show / Hide Table of Contents

    Class DisposableThreadLocal<T>

    .NET's built-in System.Threading.ThreadLocal`1 has a serious flaw: internally, it creates an array with an internal lattice structure which in turn causes the garbage collector to cause long blocking pauses when tearing the structure down. See https://ayende.com/blog/189761-A/production-postmortem-the-slow-slowdown-of-large-systems for a more detailed explanation.

    This is a completely different problem than in Java which the ClosableThreadLocal<T> class is meant to solve, so DisposableThreadLocal<T> is specific to Lucene.NET and can be used as a direct replacement for ClosableThreadLocal<T>.

    This class works around the issue by using an alternative approach than using System.Threading.ThreadLocal`1. It keeps track of each thread's local and global state in order to later optimize garbage collection. A complete explanation can be found at https://ayende.com/blog/189793-A/the-design-and-implementation-of-a-better-threadlocal-t.

    This is a Lucene.NET INTERNAL API, use at your own risk
    Inheritance
    System.Object
    DisposableThreadLocal<T>
    Implements
    System.IDisposable
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Lucene.Net.Util
    Assembly: Lucene.Net.dll
    Syntax
    public sealed class DisposableThreadLocal<T> : IDisposable
    Type Parameters
    Name Description
    T

    Specifies the type of data stored per-thread.

    Constructors

    | Improve this Doc View Source

    DisposableThreadLocal()

    Initializes the DisposableThreadLocal<T> instance.

    Declaration
    public DisposableThreadLocal()
    Remarks

    The default value of T is used to initialize the instance when Value is accessed for the first time.

    | Improve this Doc View Source

    DisposableThreadLocal(Func<T>)

    Initializes the DisposableThreadLocal<T> instance with the specified valueFactory function.

    Declaration
    public DisposableThreadLocal(Func<T> valueFactory)
    Parameters
    Type Name Description
    System.Func<T> valueFactory

    The System.Func`2 invoked to produce a lazily-initialized value when an attempt is made to retrieve Value without it having been previously initialized.

    Exceptions
    Type Condition
    System.ArgumentNullException

    valueFactory is null.

    Properties

    | Improve this Doc View Source

    IsValueCreated

    Gets whether Value is initialized on the current thread.

    Declaration
    public bool IsValueCreated { get; }
    Property Value
    Type Description
    System.Boolean
    Exceptions
    Type Condition
    System.ObjectDisposedException

    The DisposableThreadLocal<T> instance has been disposed.

    | Improve this Doc View Source

    Value

    Gets or sets the value of this instance for the current thread.

    Declaration
    public T Value { get; set; }
    Property Value
    Type Description
    T
    Remarks

    If this instance was not previously initialized for the current thread, accessing Value will attempt to initialize it. If an initialization function was supplied during the construction, that initialization will happen by invoking the function to retrieve the initial value for Value. Otherwise, the default value of T will be used.

    Exceptions
    Type Condition
    System.ObjectDisposedException

    The DisposableThreadLocal<T> instance has been disposed.

    | Improve this Doc View Source

    Values

    Gets a collection for all of the values currently stored by all of the threads that have accessed this instance.

    Declaration
    public ICollection<T> Values { get; }
    Property Value
    Type Description
    System.Collections.Generic.ICollection<T>
    Exceptions
    Type Condition
    System.ObjectDisposedException

    The DisposableThreadLocal<T> instance has been disposed.

    Methods

    | Improve this Doc View Source

    Dispose()

    Releases the resources used by this DisposableThreadLocal<T> instance.

    Declaration
    public void Dispose()
    | Improve this Doc View Source

    Get()

    Declaration
    [Obsolete("Use Value instead.")]
    public T Get()
    Returns
    Type Description
    T
    | Improve this Doc View Source

    Set(T)

    Declaration
    [Obsolete("Use Value instead.")]
    public void Set(T value)
    Parameters
    Type Name Description
    T value

    Implements

    System.IDisposable
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)