I have a runnable that downloads a file from the Internet, it looks like this:
class Downloader implements Runnable { volatile Status status; public void run() {
The status is as follows:
public enum Status { PAUSED { public int someData() { return 0; } }, INPROGRESS { public int someData() { return 1; } } public abstract int someData(); private String msg; public String getSomeMsg() { return msg; } public void setSomeMsg(String s) { msg=s; } public boolean isInProgress() { return this == INPROGRESS; } }
when the user clicks the Pause button, the status variable is set to PAUSED from the GUI stream.
The code was compiled using java 1.6 and compiled for the Android platform.
My question is, is it thread safe for installing / reading Enum as follows? Here I read a wonderful article:
http://javarevisited.blogspot.com/2011/06/volatile-keyword-java-example-tutorial.html
and I am quite sure that it is preserved, but it says little about transfers.
source share