Skip to content

Instantly share code, notes, and snippets.

@dcrystalj
Created May 23, 2014 20:01
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 dcrystalj/26de2303c4ce2a6927dd to your computer and use it in GitHub Desktop.
Save dcrystalj/26de2303c4ce2a6927dd to your computer and use it in GitHub Desktop.
semi5.java
//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