First off, a conditional expression that tests equality with two boolean operands is poor form.
if(thing.flag==false) should read if(!thing.flag)
Much nicer
No, Thread.sleep does not cause the thread to lose any monitor.
Now, what you are getting at in this case is a little bit unclear, so I will speculate. One important point to note is that 'thing' (probably if my speculation is right) should be declared volatile.
You run this piece of code, have another thread modify the value of thing (do you know when ?), and then when you run it again the value has been changed ?
This is the correct behaviour, although I don't know if this is what you mean. A
test case as such usually requires three things:
- Some source code (or equivalent depending on circumstances) so that others can reproduce the situation (granted, this is not always easy when dealing with threads).
- Your expected outcome. What did *you* think was going happen ?
- Your actual outcome.
It is very important to express your expected and actual outcomes clearly; what you have described appears to be very ambiguous.