Skip to content

Instantly share code, notes, and snippets.

@FossiFoo
Created June 19, 2015 18:55
Show Gist options
  • Save FossiFoo/7de2231f24e7b0b5214e to your computer and use it in GitHub Desktop.
Save FossiFoo/7de2231f24e7b0b5214e to your computer and use it in GitHub Desktop.
withTimeout does not fail task after timeout
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.Test;
import com.linkedin.parseq.Engine;
import com.linkedin.parseq.EngineBuilder;
import com.linkedin.parseq.Task;
@Test
public class ParseqTest {
public static void testParallelTasks() throws InterruptedException {
final Task<Void> noReturn = Task.action( () -> { while ( true ) {} } )
.withTimeout( 100, TimeUnit.MILLISECONDS );
final int numCores = Runtime.getRuntime().availableProcessors();
final ExecutorService taskScheduler = Executors.newFixedThreadPool(numCores + 1);
final ScheduledExecutorService timerScheduler = Executors.newSingleThreadScheduledExecutor();
final Engine engine = new EngineBuilder()
.setTaskExecutor(taskScheduler)
.setTimerScheduler(timerScheduler)
.build();
engine.run( noReturn );
noReturn.await( );
System.out.print( "will never reach: " + noReturn.get() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment