java - Will making a variable volatile work if I take copy it to another variable and try to change that? -


I have an Android application object (though it is purely a question of a Java which I believe)

I also understand, the way I used the unstable right, I was unstable as to have defined AppData application automatically guarantee are that all variables within AppData object (Each of them, having complex objects like arrays Are themselves too unstable) or I need to clearly make them unstable like what I have done

Morever, as I mentioned in the question marked in the comments, Equating a new variable x to an unstable variable makes x even unstable?

Extension of the public-class app {Private volatile static appetizer apadiata; Public void FetchMePageInfo (long idOfUserIfNotForSelf) {RestService.getMePageInfo (new callback & lt; MePageInfo & gt; () {// RestService just another class that calls the Web server, and stable method getMepageInfo @Override public void success ( for MePageInfo newMePageInfo, north response) {// successful server request, store newly I fetched two own set of page // referee in array to me to page ref = show me page = new object, ArrayList & LT; MePageInfo & gt; mPageInfoList = appData.getMePageInfoList (); // Question: AppData is unstable, but that mPageInfoList means also threadsafe MePageInfo selfRef = appData.getUserMePageInfo (); if (selfRef = null!) {// if I page already exists, as well as my current page remove mPageInfoList.remove are? (Atmrf);} mPageInfoList.add (newMePageInfo); appData.setUserMePageInfo (newMePageInfo); // does not automatically change the call listeners}}); }} Public Square AppData {/ ** This is the MePageInfo objects of various other users that users can go to bring instantly to the server ** instead of calling / server / volatile ArrayList & lt; MePageInfo & gt; MePageInfoList = New Arrestist & lt; MePageInfo & gt; (); // MyPageInfo field for data entry ** ** MyPageInfo for user's login, this is zero in the beginning and the user is filled with FetchGenericMePageInfo for unstable MePageInfo userMePageInfo = Null; }

Volatiles and thread are not the only thing safe unstable Guarantees you that

  1. Write a on the volatile variable and after the after reading this variable a relation - establishes the relationship first Between threads

  2. All of these special variables read and write atoms.

This is what that does. So if you specify the value of each other for a variable variable, do not make it unstable . The concept of thread security is more complex and the fact that a variable is unstable does not mean that it is itself thread-protected.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -