Dalvik VM & Java Memory Model (Concurrent programming on Android)

前端 未结 4 1942
名媛妹妹
名媛妹妹 2021-01-30 07:04

I am working on Android projects which involve the lot of concurrent programming and I am going to implement some custom inter-threads communication stuff (the one from

4条回答
  •  天涯浪人
    2021-01-30 07:15

    I haven't read your question completely, but first of all do not use volatile, even opengles coders do not use it for different ui vs renderer threads.

    Use volatile if and only if one thread writes (say to some class' static property) and other reads, even then you have to synchronize, read this for some good ways to handle counts

    How to synchronize a static variable among threads running different instances of a class in java?

    1. always use synchronize
    2. do not jump at large projects for such difficult topics like concurrent programming
    3. go through android samples on games where they have discussed the concept of runnables, handlers, and exchanging messages b/w threads (UI THREAD AND RENDERER THREAD).

提交回复
热议问题