Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions practice/volatile1/RunVolatile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package volatile1;

public class RunVolatile {
public static void main(String[] args) {
RunVolatile runVolatile = new RunVolatile();
runVolatile.runVolatitleSample();
}

public void runVolatitleSample() {
VolatileSample sample = new VolatileSample();
sample.start();

try {
Thread.sleep(1000);
} catch(Exception e) {
e.printStackTrace();
}

System.out.println("RunVolatitle : sleep() end ");
sample.setDouble(-1);
System.out.println("RunVolatitle : Set value is completed !");

}
}
22 changes: 22 additions & 0 deletions practice/volatile1/VolatileSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package volatile1;

public class VolatileSample extends Thread {

private double instanceVariable = 0;

void setDouble(double value) {
this.instanceVariable = value;
}

public void run() {
System.out.println("--------------------- VolatileSample : run() start ");

while(instanceVariable == 0) {
System.out.println("--------------------- VolatileSample : while ing... ");
}

System.out.println("--------------------- VolatileSample : instanceVariable : "+instanceVariable);

System.out.println("--------------------- VolatileSample : run() end ");
}
}