Does JavaME and/or Proguard reorder assignments?

Posted by chrisdew on Stack Overflow See other posts from Stack Overflow or by chrisdew
Published on 2012-09-26T08:54:51Z Indexed on 2012/09/26 21:37 UTC
Read the original article Hit count: 337

This is a simplified example - I have two threads:

Can JavaME and/Proguard ever reorder the obX = ... statements, such that thread_B will have a null pointer exception at ob2.someMethod?

thread_A:

Object ob1 = null;
Object ob2 = null;
...
ob1 = something1;
ob2 = something2;

thread_B:

if (ob2 != null) {
    ob1.someMethod();
    ...
}

P.S. I do realise that synchronising these will avoid the issue. Synchronisation has both a performance overhead, and more importantly, a chance to introduce deadlock.

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading