Setup and TearDown executed by different threads

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Aug 13 11:48:50 UTC 2014


On 08/13/2014 03:41 PM, vyazelenko at yahoo.com wrote:
> My use-case: start server in @Setup(Level.Trial) and shutdown server
> in @TearDown(Level.Trial). And of course I want to setup some data
> for entire benchmark and remove it at the end. In other words I'm
> looking for a way to perform per-Benchmark work irrespective of
> @State configuration. 

Aha. @State(Scope.Benchmark) it is.

> And this work should be done by the same
> thread. In my case there is a session attached via ThreadLocal in
> @Setup.

Thinking out loud now.

Scope.Benchmark assumes the state is shared between the threads, which
forces users to do additional housekeeping when accessed from multiple
threads. My concern is that tracking the @Setup/@TearDown callers would
blur this for users: instead of blowing up early, users will experience
weird visibility problems caused by the lack of appropriate
synchronization.

I think you can do something like that with:
http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_29_StatesDAG.java

-Aleksey.




More information about the jmh-dev mailing list