Skip to content

Instantly share code, notes, and snippets.

@madsunrise
Created July 6, 2018 14:47
Show Gist options
  • Save madsunrise/b8560c60761f9ca2056c5f2134abd799 to your computer and use it in GitHub Desktop.
Save madsunrise/b8560c60761f9ca2056c5f2134abd799 to your computer and use it in GitHub Desktop.
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