Created
December 5, 2018 00:51
-
-
Save lihongjie0209/26c966b808c03075427d7c72ff34a707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CounterForVisibility extends Thread { | |
private volatile static int count = 0; | |
public static synchronized int getCount() { | |
return count; | |
} | |
public synchronized void setCount(int count) { | |
this.count = count; | |
} | |
public static void main(String[] args) throws InterruptedException { | |
CounterForVisibility counter = new CounterForVisibility(); | |
counter.start(); | |
Thread.sleep(100); | |
System.out.println("把计数器设置为1"); | |
counter.setCount(1); | |
} | |
@Override | |
public void run() { | |
while (Counter.getCount() == 0) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment