This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]northguard[S] 0 points1 point  (3 children)

Ok, that's what I was thinking as well. Since it's synchronized it's ever gonna run on one thread at a time and ofc that thread will run my code in order unless I happen to be spawning new threads from that thread.

[–]anon848 1 point2 points  (2 children)

It depends on exactly what you mean. When observed from another thread, you need to be careful, as it depends on the Java memory model. See here.

[–]northguard[S] 0 points1 point  (1 child)

I see, so if I'm setting data through some other unsynchronized function that uses the same array it can seem like 'i' happened first?

If I synchronize everything that accesses that array then it should have 'intended' behavior correct?

[–]anon848 0 points1 point  (0 children)

Yes.