import java.util.ArrayList; | |
class MissingSyncExample extends Thread { | |
private static int counter = 0; | |
public static void main(String[] args) throws Exception { | |
ArrayList<MissingSyncExample> threads = new ArrayList<MissingSyncExample>(); | |
// Create 10 threads | |
for (int i = 0; i < 10; i++) { | |
MissingSyncExample thread = new MissingSyncExample(); | |
thread.start(); | |
threads.add(thread); | |
} | |
// Wait for all threads to finish | |
for (MissingSyncExample thread : threads) { | |
thread.join(); | |
} | |
System.out.println(counter); | |
} | |
// The function that will be called in each thread | |
public void run() { | |
for (int i = 0; i < 100_000; i++) { | |
counter += 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment