Created
July 6, 2018 14:47
-
-
Save madsunrise/b8560c60761f9ca2056c5f2134abd799 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| int a = 0; | |
| private void test() { | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| for (int i = 0; i < 10_000; ++i) { | |
| a++; | |
| } | |
| } | |
| }).start(); | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| for (int i = 0; i < 10_000; ++i) { | |
| a--; | |
| } | |
| } | |
| }).start(); | |
| // ждем завершения потоков (через join например) | |
| System.out.println(a); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment