How to demonstrate java multithreading visibility problems?

Posted by Joe23 on Stack Overflow See other posts from Stack Overflow or by Joe23
Published on 2010-05-07T08:08:12Z Indexed on 2010/05/07 8:18 UTC
Read the original article Hit count: 370

Filed under:
|
|

If variables in Java are accessed from multiple threads, one must ensure that they are safely published. This usually means using synchronizedor volatile.

I have got the impression, that some of my colleagues do not take this issue seriously, since they "never heard of volatile before and their programs have worked for years".

So my question is:

Can someone provide an example Java program/snippet, that reliably shows data visibility problems.

I think running a program and seeing the unexpected NPE or stale variable value would help more, than just theoretic explanations, that cannot be demonstrated.

Thanks a lot for your help!

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading