List of usage examples for java.util.concurrent RunnableFuture run
void run();
From source file:net.dryuf.concurrent.benchmark.BenchmarkSupport.java
public static void threadedRunFutures(RunnableFuture<Integer>[] array) { Thread t = new Thread(() -> { for (RunnableFuture<Integer> v : array) { v.run(); }//from www . ja v a2s. c o m }); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:org.apache.flink.runtime.state.StateSnapshotCompressionTest.java
private void snapshotRestoreRoundtrip(boolean useCompression) throws Exception { ExecutionConfig executionConfig = new ExecutionConfig(); executionConfig.setUseSnapshotCompression(useCompression); KeyedStateHandle stateHandle = null; ValueStateDescriptor<String> stateDescriptor = new ValueStateDescriptor<>("test", String.class); stateDescriptor.initializeSerializerUnlessSet(executionConfig); AbstractKeyedStateBackend<String> stateBackend = new HeapKeyedStateBackend<>( mock(TaskKvStateRegistry.class), StringSerializer.INSTANCE, StateSnapshotCompressionTest.class.getClassLoader(), 16, new KeyGroupRange(0, 15), true, executionConfig, TestLocalRecoveryConfig.disabled(), mock(HeapPriorityQueueSetFactory.class), TtlTimeProvider.DEFAULT);//w ww . j a v a 2 s . c o m try { InternalValueState<String, VoidNamespace, String> state = stateBackend .createInternalState(new VoidNamespaceSerializer(), stateDescriptor); stateBackend.setCurrentKey("A"); state.setCurrentNamespace(VoidNamespace.INSTANCE); state.update("42"); stateBackend.setCurrentKey("B"); state.setCurrentNamespace(VoidNamespace.INSTANCE); state.update("43"); stateBackend.setCurrentKey("C"); state.setCurrentNamespace(VoidNamespace.INSTANCE); state.update("44"); stateBackend.setCurrentKey("D"); state.setCurrentNamespace(VoidNamespace.INSTANCE); state.update("45"); CheckpointStreamFactory streamFactory = new MemCheckpointStreamFactory(4 * 1024 * 1024); RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot = stateBackend.snapshot(0L, 0L, streamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()); snapshot.run(); SnapshotResult<KeyedStateHandle> snapshotResult = snapshot.get(); stateHandle = snapshotResult.getJobManagerOwnedSnapshot(); } finally { IOUtils.closeQuietly(stateBackend); stateBackend.dispose(); } executionConfig = new ExecutionConfig(); stateBackend = new HeapKeyedStateBackend<>(mock(TaskKvStateRegistry.class), StringSerializer.INSTANCE, StateSnapshotCompressionTest.class.getClassLoader(), 16, new KeyGroupRange(0, 15), true, executionConfig, TestLocalRecoveryConfig.disabled(), mock(HeapPriorityQueueSetFactory.class), TtlTimeProvider.DEFAULT); try { stateBackend.restore(StateObjectCollection.singleton(stateHandle)); InternalValueState<String, VoidNamespace, String> state = stateBackend .createInternalState(new VoidNamespaceSerializer(), stateDescriptor); stateBackend.setCurrentKey("A"); state.setCurrentNamespace(VoidNamespace.INSTANCE); Assert.assertEquals("42", state.value()); stateBackend.setCurrentKey("B"); state.setCurrentNamespace(VoidNamespace.INSTANCE); Assert.assertEquals("43", state.value()); stateBackend.setCurrentKey("C"); state.setCurrentNamespace(VoidNamespace.INSTANCE); Assert.assertEquals("44", state.value()); stateBackend.setCurrentKey("D"); state.setCurrentNamespace(VoidNamespace.INSTANCE); Assert.assertEquals("45", state.value()); } finally { IOUtils.closeQuietly(stateBackend); stateBackend.dispose(); } }