当前位置: 首页>>代码示例>>Java>>正文


Java RunnableFuture.cancel方法代码示例

本文整理汇总了Java中java.util.concurrent.RunnableFuture.cancel方法的典型用法代码示例。如果您正苦于以下问题:Java RunnableFuture.cancel方法的具体用法?Java RunnableFuture.cancel怎么用?Java RunnableFuture.cancel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.RunnableFuture的用法示例。


在下文中一共展示了RunnableFuture.cancel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDismissingSnapshotNotRunnable

import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testDismissingSnapshotNotRunnable() throws Exception {
	setupRocksKeyedStateBackend();
	try {
		RunnableFuture<KeyedStateHandle> snapshot =
			keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpoint());
		snapshot.cancel(true);
		Thread asyncSnapshotThread = new Thread(snapshot);
		asyncSnapshotThread.start();
		try {
			snapshot.get();
			fail();
		} catch (Exception ignored) {

		}
		asyncSnapshotThread.join();
		verifyRocksObjectsReleased();
	} finally {
		this.keyedStateBackend.dispose();
		this.keyedStateBackend = null;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:23,代码来源:RocksDBStateBackendTest.java

示例2: discardStateFuture

import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
/**
 * Discards the given state future by first trying to cancel it. If this is not possible, then
 * the state object contained in the future is calculated and afterwards discarded.
 *
 * @param stateFuture to be discarded
 * @throws Exception if the discard operation failed
 */
public static void discardStateFuture(RunnableFuture<? extends StateObject> stateFuture) throws Exception {
	if (null != stateFuture) {
		if (!stateFuture.cancel(true)) {

			try {
				// We attempt to get a result, in case the future completed before cancellation.
				StateObject stateObject = FutureUtil.runIfNotDoneAndGet(stateFuture);

				if (null != stateObject) {
					stateObject.discardState();
				}
			} catch (CancellationException | ExecutionException ex) {
				LOG.debug("Cancelled execution of snapshot future runnable. Cancellation produced the following " +
					"exception, which is expected an can be ignored.", ex);
			}
		}
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:26,代码来源:StateUtil.java

示例3: testDismissingSnapshot

import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testDismissingSnapshot() throws Exception {
	setupRocksKeyedStateBackend();
	try {
		RunnableFuture<KeyedStateHandle> snapshot =
			keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpoint());
		snapshot.cancel(true);
		verifyRocksObjectsReleased();
	} finally {
		this.keyedStateBackend.dispose();
		this.keyedStateBackend = null;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:RocksDBStateBackendTest.java

示例4: testCancelRunningSnapshot

import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testCancelRunningSnapshot() throws Exception {
	setupRocksKeyedStateBackend();
	try {
		RunnableFuture<KeyedStateHandle> snapshot = keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpoint());
		Thread asyncSnapshotThread = new Thread(snapshot);
		asyncSnapshotThread.start();
		waiter.await(); // wait for snapshot to run
		waiter.reset();
		runStateUpdates();
		snapshot.cancel(true);
		blocker.trigger(); // allow checkpointing to start writing
		assertTrue(testStreamFactory.getLastCreatedStream().isClosed());
		waiter.await(); // wait for snapshot stream writing to run
		try {
			snapshot.get();
			fail();
		} catch (Exception ignored) {
		}

		asyncSnapshotThread.join();
		verifyRocksObjectsReleased();
	} finally {
		this.keyedStateBackend.dispose();
		this.keyedStateBackend = null;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:28,代码来源:RocksDBStateBackendTest.java

示例5: testSnapshotAsyncCancel

import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testSnapshotAsyncCancel() throws Exception {
	DefaultOperatorStateBackend operatorStateBackend =
			new DefaultOperatorStateBackend(OperatorStateBackendTest.class.getClassLoader(), new ExecutionConfig(), true);

	ListStateDescriptor<MutableType> stateDescriptor1 =
			new ListStateDescriptor<>("test1", new JavaSerializer<MutableType>());

	ListState<MutableType> listState1 = operatorStateBackend.getOperatorState(stateDescriptor1);


	listState1.add(MutableType.of(42));
	listState1.add(MutableType.of(4711));

	BlockerCheckpointStreamFactory streamFactory = new BlockerCheckpointStreamFactory(1024 * 1024);

	OneShotLatch waiterLatch = new OneShotLatch();
	OneShotLatch blockerLatch = new OneShotLatch();

	streamFactory.setWaiterLatch(waiterLatch);
	streamFactory.setBlockerLatch(blockerLatch);

	RunnableFuture<OperatorStateHandle> runnableFuture =
			operatorStateBackend.snapshot(1, 1, streamFactory, CheckpointOptions.forCheckpoint());

	ExecutorService executorService = Executors.newFixedThreadPool(1);

	executorService.submit(runnableFuture);

	// wait until the async checkpoint is in the stream's write code, then continue
	waiterLatch.await();

	// cancel the future, which should close the underlying stream
	runnableFuture.cancel(true);
	Assert.assertTrue(streamFactory.getLastCreatedStream().isClosed());

	// we allow the stream under test to proceed
	blockerLatch.trigger();

	try {
		runnableFuture.get(60, TimeUnit.SECONDS);
		Assert.fail();
	} catch (CancellationException ignore) {
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:46,代码来源:OperatorStateBackendTest.java


注:本文中的java.util.concurrent.RunnableFuture.cancel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。