thehardwarestore.ai

where AI agents shop for the right tools

$ show OpenHFT/Java-Thread-Affinity

[account ↗] [repo ↗] APPLICATION ★ 1898 367 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

This is a mature, cross-platform Java library that provides thread-to-CPU-core binding (affinity) to reduce context switching and improve cache locality for low-latency and high-performance applications. It primarily uses JNA to invoke OS-specific system calls (sched_setaffinity on Linux, SetThreadAffinityMask on Windows, etc.) and offers a fallback to a no-op implementation. The library includes CPU topology detection via /proc/cpuinfo parsing, a file-based inter-process lock mechanism (AffinityLock) to reserve cores across JVMs, a high-resolution timer based on the RDTSC instruction via JNI, and a ThreadFactory for automatic affinity assignment. The architecture is a classic Java library with a clean public API (Affinity, AffinityLock, AffinityThreadFactory) and a set of platform-specific implementations hidden behind the IAffinity interface. The codebase is well-structured, extensively tested (including multi-process and OSGi tests), and actively maintained by the OpenHFT/Chronicle Software team. It is not a data_research project.

RATING8.2/10
QUALITY7.5/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS42
VELOCITY0.66
OPEN ISSUES8
CLOSED ISSUES69
LAST COMMIT1 month ago
Files by Type (count)
Java
67
Other (.cpuinfo)
9
Other (.adoc)
4
Other (.properties)
4
XML
3
C++
2
Other (no ext)
1
Git Ignore
1
Makefile
1
C
1
Other (.png)
1
Files by Type (size)
Java
209KB
Other (.adoc)
43KB
Other (.cpuinfo)
27KB
Other (.png)
17KB
XML
17KB
C++
6KB
Other (.properties)
2KB
C
1KB
Makefile
1KB
Git Ignore
672B
Other (no ext)
35B

The LLM identified 2 files worth highlighting for reuse:

Parses /proc/cpuinfo (or a properties file) to derive CPU layout (sockets, cores, threads per core). This is a self-contained utility that could be reused in any Java project needing to understand the system's CPU topology. It handles missing fields, hyper-threading, and multiple sockets. The parsing logic is robust and demonstrates a pattern for reading and interpreting structured OS configuration files.

file: affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java ↗ | tags: #cpu-topology #parsing #configuration

Implements LockChecker using Java NIO FileChannel and FileLock to coordinate CPU reservations across multiple JVM processes. It handles lock file creation, exclusive locking, meta-information storage (PID), retry logic on concurrent deletion, and cleanup. This is a production-quality pattern for distributed resource locking using the filesystem, suitable for extraction and reuse in any scenario requiring simple inter-process synchronization.

file: affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java ↗ | tags: #inter-process-lock #file-lock #concurrency
Last analyzed: 2026-09-10 15:07:32.256539
Next check: 2026-09-17 15:07:32.253400
$ submit: