Created
May 20, 2018 14:52
-
-
Save ThanawatMas/07e2f7421cd59595cbb18bb6d4be7a16 to your computer and use it in GitHub Desktop.
ConcurrentModificationSolution
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
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