On 9/27/2011 9:32 AM, sebastian_bugiu wrote: > Still I cannot understand why creating an > object in the UI thread and accessing it in another newly created > thread (created in the UI thread that initialized the object) does not > work. After creation the object is only accessed from the new thread, > never from another.
Listen, I'm not a Java expert, but if you're not using synchronization primitives, then Java could execute code in one thread IN ANY ORDER, as long as dependencies in that thread aren't violated, and you would never know the difference -- except for the fact that another thread is making assumptions about the order of operations in the first thread. "I cannot understand why..." This is why I suggested you talk to a Java threading expert. I can't tell you if what I just said is correct -- though I know it can be correct at the CPU level at this point with out-of-order execution possible. Also consider that one thread may be caching results before committing them -- your object may be created but not stored in the global (sorry, "static final"). The general rule is you can't make ANY assumptions about data from one thread being available in another thread unless you're using synchronization primitives. Tim -- You received this message because you are subscribed to the Google Groups "Android Discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/android-discuss?hl=en.
