Created
May 23, 2014 20:01
-
-
Save dcrystalj/26de2303c4ce2a6927dd to your computer and use it in GitHub Desktop.
semi5.java
This file contains 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
//long startTime = System.currentTimeMillis(); | |
initGrid(grid); | |
initWords(words); | |
//long startTime1 = System.currentTimeMillis(); | |
maxThreads--; | |
Vector<String> output = new Vector<String>(); | |
if(maxThreads < 1) { | |
for (int i = 0; i < grid.length; i++) { | |
output.addAll( | |
new Grid(GRID, TRANSPOSED_GRID, FLIPPED_GRID, WORDS, i).getWordFromLine() | |
); | |
} | |
} | |
else { | |
ExecutorService executor = Executors.newFixedThreadPool(maxThreads); // We'll use a thread pool with a fixed number of threads. | |
Vector<Future<Vector<String>>> futureVector = new Vector<Future<Vector<String>>>(); // The result of each simulation is the indicator of who won. | |
for (int i = 0; i < grid.length; i++) { | |
Future<Vector<String>> future = executor.submit( | |
new Grid(GRID, TRANSPOSED_GRID, FLIPPED_GRID, WORDS, i) | |
); | |
futureVector.add(future); | |
} | |
for (Future<Vector<String>> fut : futureVector) { | |
try { | |
output.addAll(fut.get()); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
executor.shutdown(); | |
} | |
/*long time = System.currentTimeMillis() - startTime; | |
long time1 = System.currentTimeMillis() - startTime1; | |
System.out.println("Time:" + time); | |
System.out.println("Time1:" + time1);*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment