Permalink
Browse files

Add timeout for Future.get() when finishing test

  • Loading branch information...
1 parent 7889997 commit 0bf1651ee114ef554a01ec7aea9ce293047a105b @apcj apcj committed Aug 15, 2011
Showing with 15 additions and 11 deletions.
  1. +15 −11 src/main/java/org/neo4j/bench/cases/mixedload/MixedLoadBenchCase.java
@@ -97,7 +97,14 @@ public void run( GraphDatabaseService graphDb )
{
int maxThreads = Runtime.getRuntime().availableProcessors() + 2;
- ExecutorService service = Executors.newFixedThreadPool( maxThreads );
+ ExecutorService service = Executors.newFixedThreadPool( maxThreads, new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread thread = new Thread(r);
+ thread.setDaemon(true);
+ return thread;
+ }
+ } );
Random r = new Random();
long startTime = System.currentTimeMillis();
@@ -152,11 +159,8 @@ else if ( dice > 0.1 )
e.printStackTrace();
}
}
- try {
- service.awaitTermination(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+
+ service.shutdown();
System.out.println("Service shut-down complete");
try
{
@@ -207,7 +211,7 @@ private void gatherUp( List<Future<int[]>> tasks, WorkerType type,
tasksExecuted++;
try
{
- int[] taskRes = task.get();
+ int[] taskRes = task.get(5, TimeUnit.SECONDS);
totalReads += taskRes[0];
totalWrites += taskRes[1];
totalTime += taskRes[2];
@@ -237,11 +241,11 @@ private void gatherUp( List<Future<int[]>> tasks, WorkerType type,
}
catch ( ExecutionException e )
{
- // It threw an exception, print and continue
e.printStackTrace();
- continue;
- }
- finally
+ } catch (TimeoutException e) {
+ System.err.println("Task failed to terminate: " + task);
+ e.printStackTrace();
+ } finally
{
it.remove();
}

0 comments on commit 0bf1651

Please sign in to comment.