Class ThreadAffinity


  • public final class ThreadAffinity
    extends Object
    Provides interface to OpenHFT Thread Affinity Library based on a given ThreadAffinityConfigure. The idea is that by binding a thread to a core thread performance is improved. But this improvement can only be realized if the core is isolated from operating system use. Otherwise the thread still faces losing its core to the OS, having to wait to gain the core again with its cache wrecked by the OS thread.

    Please see ThreadAffinityConfigure for a detailed discussion on how to configure thread affinity.

    This class is designed for use with net.sf.eBus.net.SelectorThread and net.sf.eBus.net.client.EClient.RQThread both of which may be bound to a core. This would normally be done when the thread is configured as spinning.

    Author:
    Charles W. Rapp
    See Also:
    ThreadAffinityConfigure
    • Method Detail

      • acquireLock

        public static net.openhft.affinity.AffinityLock acquireLock​(net.openhft.affinity.AffinityLock lock,
                                                                    ThreadAffinityConfigure config)
        Returns an OpenHFT thread affinity lock based on an existing lock and CPU strategy configuration. The idea is OpenHFT will select a CPU based on the existing lock's CPU and the CPU selection strategies. Please not that the final strategy is AffinityStrategies.ANY allowing any CPU to be chosen if no available CPU matches the previous strategies.
        Parameters:
        lock - existing affinity lock.
        config - CPU selection strategy.
        Returns:
        thread affinity lock. This lock should be released when the thread stops.
        Throws:
        NullPointerException - if lock or config is null.
        IllegalArgumentException - if config affinity type is not AffinityType.CPU_STRATEGIES.
        See Also:
        acquireLock(ThreadAffinityConfigure)