Re: InterleavedRunner: Class not instrumented

Skip to first unread message

Alasdair Mackintosh

Sep 19, 2011, 6:51:51 PM9/19/11
On Mon, Sep 19, 2011 at 10:15 AM, burny <> wrote:
> Hi,
> I tried to create an interleaved test thingy for a class with at
> least(!) one race condition/multithreadin issue in it, which I already
> was able to reproduce using stuff from the very bottom of the thread-
> weaver wiki entry.

I'll try and take a look tomorrow.



Sep 21, 2011, 6:32:58 AM9/21/11
to Thread Weaver
Thanks thats kind of you :)

On 20 Sep., 00:51, Alasdair Mackintosh <>

Alasdair Mackintosh

Sep 21, 2011, 7:29:35 PM9/21/11
On Mon, Sep 19, 2011 at 3:51 PM, Alasdair Mackintosh
<> wrote:
> I'll try and take a look tomorrow.

The problem is that your test is using the wrong annotations. You need
to use the ThreadedTest annotation to indicate which methods you want
the framework to run. See below.

// This method is run by JUnit. Name it testXXX, or use the @Test annotation
public void testThreading() {
ThreadedTestRunner runner = new ThreadedTestRunner();
// Run all Weaver tests in this class, using DateTime as the Class
Under Test.
runner.runTests(this.getClass(), DateTime.class);

// This test method is invoked by the ThreadWeaver framework
// AFTER the framework has loaded and instrumented the test classes.
public void runDateTimeTest() throws Throwable {
MainTest main = new MainTest();
SecondaryTest secondary = new SecondaryTest();

Explanation - in order to pause your test at the right time,
Threadweaver has to load your classes via a special classloader, so
that it can add some instrumentation. The ThreadedTestRunner is
responsible for reloading your test classes with a custom classloader
that does the necessary work.

BUT, I'm afraid that this approach still isn't going to work for you.
The reason is that the InterleavedRunner only does single
interleaving. For example, if you method has 4 lines then it will:

start thread 1 and pause at line 1
let thread 2 run
resume thread 1

reset all objects

start thread 1 and pause at line 2
let thread 2 run
resume thread 1

So you won't get the complex interleaving you need.

For that to work, you'd need to use explicit breakpoints, or the
scripting interface, so that you can run thread 1, then pause it and
run thread 2, then pause that and rerun thread 1, and so forth. See
the Wiki for more details.

Hope this helps,


Reply all
Reply to author
0 new messages