public class AffinityLock extends Object implements Closeable
Modifier and Type | Field and Description |
---|---|
static String |
AFFINITY_RESERVED |
static BitSet |
BASE_AFFINITY |
static int |
PROCESSORS |
static BitSet |
RESERVED_AFFINITY |
Modifier and Type | Method and Description |
---|---|
static AffinityLock |
acquireCore()
Assign any free core to this thread.
|
static AffinityLock |
acquireCore(boolean bind)
Assign a core(and all its cpus) which can be bound to the current thread or another thread.
|
static AffinityLock |
acquireLock()
Assign any free cpu to this thread.
|
AffinityLock |
acquireLock(AffinityStrategy... strategies)
Give another affinity lock relative to this one based on a list of strategies.
|
static AffinityLock |
acquireLock(boolean bind)
Assign a cpu which can be bound to the current thread or another thread.
|
void |
bind()
Bind the current thread to this reservable lock.
|
void |
bind(boolean wholeCore)
Bind the current thread to this reservable lock.
|
void |
close() |
int |
cpuId() |
static @NotNull CpuLayout |
cpuLayout() |
static void |
cpuLayout(@NotNull CpuLayout cpuLayout)
Set the CPU layout for this machine.
|
static @NotNull String |
dumpLocks() |
protected void |
finalize() |
boolean |
isAllocated() |
boolean |
isBound() |
void |
release()
Release the current AffinityLock which can be discarded.
|
String |
toString() |
public static final String AFFINITY_RESERVED
public static final int PROCESSORS
public static final BitSet BASE_AFFINITY
public static final BitSet RESERVED_AFFINITY
public static void cpuLayout(@NotNull @NotNull CpuLayout cpuLayout)
Changing the layout will have no impact on thread which have already been assigned. It only affects subsequent assignments.
cpuLayout
- for this application to use for this machine.@NotNull public static @NotNull CpuLayout cpuLayout()
public static AffinityLock acquireLock()
public static AffinityLock acquireCore()
In reality, only one cpu is assigned, the rest of the threads for that core are reservable so they are not used.
public static AffinityLock acquireLock(boolean bind)
This can be used for defining your thread layout centrally and passing the handle via dependency injection.
bind
- if true, bind the current thread, if false, reserve a cpu which can be bound later.public static AffinityLock acquireCore(boolean bind)
This can be used for defining your thread layout centrally and passing the handle via dependency injection.
bind
- if true, bind the current thread, if false, reserve a cpu which can be bound later.@NotNull public static @NotNull String dumpLocks()
public void bind()
public void bind(boolean wholeCore)
wholeCore
- if true, also reserve the whole core.public AffinityLock acquireLock(AffinityStrategy... strategies)
The strategies are evaluated in order to (like a search path) to find the next appropriate thread. If ANY is not the last strategy, a warning is logged and no cpu is assigned (leaving the OS to choose)
strategies
- To determine if you want the same/different core/socket.public void release()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
protected void finalize() throws Throwable
public int cpuId()
public boolean isAllocated()
public boolean isBound()
Copyright © 2017. All rights reserved.