JMH Question: execution of code when iteration completes before TearDown

Aleksey Shipilev shade at
Tue Sep 27 12:54:18 UTC 2016

On 09/26/2016 05:15 PM, Lev Serebryakov wrote:
> On 23.09.2016 09:24, Aleksey Shipilev wrote:
>>> I have asymmetric JMH test for a blocking queue-like data structure and
>>> can't find what's proper way to execute actions that will unblock treads
>>> blocking on my queue in JMH. I've supposed to do "unblocking" in @TearDown
>>> part of thread-specific state but it seems like @TearDown is not executed
>>> till all threads are finished.
>> See this sample:
>  It works, but here is one missing bit in JMH, needed for such
> benchmarks, IMHO: thread-level setup method. As result, I have
> handrolled framework to test different implementations of blocking ring
> buffer specific to my task, because some implementations of (my)
> interest need some initialization, which should be done in context of
> working threads (it assume, that reader and writer threads are never
> changed after setup, which is valid for my task), but only once before
> data pumping. 

How's that different from making an additional @State(Thread) object,
and store the thread-local data there? Its @Setup/@TearDown methods
would be touched by the worker thread only:

It can even initialize after the shared @State(Benchmark) object:


More information about the jmh-dev mailing list