Skip to content

Instantly share code, notes, and snippets.

@af463419014
Last active February 3, 2019 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save af463419014/6814e807684c46bda34349608d9f5882 to your computer and use it in GitHub Desktop.
Save af463419014/6814e807684c46bda34349608d9f5882 to your computer and use it in GitHub Desktop.
public class A {
private static int N = 1000;
private static K kk[] = new K[N];
public static void main(String[] args) throws Exception {
for (int i = 0; i < N; i++) {
kk[i] = new K();
}
for (int i = 0; i < N; i++) {
final K k = kk[i];
new Thread() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
k.init();
}
}.start();
new Thread() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
k.run();
}
}.start();
}
Thread.sleep(3000);
int rs[] = new int[N];
for (int i = 0; i < N; i++) {
rs[kk[i].out]++;
}
System.out.println("0:" + rs[0]);
System.out.println("1:" + rs[1]);
System.out.println("10:" + rs[10]);
System.out.println("11:" + rs[11]);
}
}
class K {
int in = 0, inited = 0;
int out;
void init() {
in = 10;
inited = 1;
}
void run() {
out = in + inited;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment