Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ThanawatMas/07e2f7421cd59595cbb18bb6d4be7a16 to your computer and use it in GitHub Desktop.
Save ThanawatMas/07e2f7421cd59595cbb18bb6d4be7a16 to your computer and use it in GitHub Desktop.
ConcurrentModificationSolution
public abstract class ConcurrentModificationSolution extends ConcurrentModificationProblem {
final void solve() {
ArrayList<String> roundList = experimentData();
String newItem = "C";
System.out.println("************************** Solve by " + solutionName());
System.out.println("Before : " + roundList);
try {
long start = System.currentTimeMillis();
addItemAndReIndex(roundList, newItem);
long finish = System.currentTimeMillis() - start;
System.out.println("After : " +roundList + " times: " + finish + " ms");
} catch (ConcurrentModificationException ex) {
System.out.println("Not Solve!!!! >>>>>>>>>>>>>>> found " + ex);
ex.printStackTrace();
}
}
public abstract String solutionName();
public static void main(String[] args) {
ConcurrentModificationSolution[] solutions = {
new SolveByCopyOnWriteArrayList(),
new SolveByCopyToRemove(),
new SolveByInnosense(),
new SolveByIterator(),
new SolveByJava8RemoveIf(),
new SolveByJava8Stream(),
new SolveBySomeSense()
};
for (ConcurrentModificationSolution solution :
solutions) {
solution.solve();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment