org.apache.flink.runtime.taskmanager.DispatcherThreadFactory Java Examples

The following examples show how to use org.apache.flink.runtime.taskmanager.DispatcherThreadFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudHBaseSinkFunction.java    From alibaba-flink-connectors with Apache License 2.0 5 votes vote down vote up
private void startFlusher() {
	this.flusher = new ScheduledThreadPoolExecutor(1,
			new DispatcherThreadFactory(Thread.currentThread().getThreadGroup(), "CloudHBase Flusher"));
	this.flusher.setRemoveOnCancelPolicy(true);
	this.flusher.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
	this.flusher.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);

	this.flusher.scheduleAtFixedRate(() -> {
		if (System.currentTimeMillis() - lastFlushTime >= flushInterval) {
			flush(false);
		}
	}, flushInterval, flushInterval, TimeUnit.MILLISECONDS);
}
 
Example #2
Source File: StreamTask.java    From flink with Apache License 2.0 4 votes vote down vote up
protected StreamTask(
		Environment environment,
		@Nullable TimerService timerService,
		Thread.UncaughtExceptionHandler uncaughtExceptionHandler,
		StreamTaskActionExecutor actionExecutor,
		TaskMailbox mailbox) throws Exception {

	super(environment);

	this.configuration = new StreamConfig(getTaskConfiguration());
	this.recordWriter = createRecordWriterDelegate(configuration, environment);
	this.actionExecutor = Preconditions.checkNotNull(actionExecutor);
	this.mailboxProcessor = new MailboxProcessor(this::processInput, mailbox, actionExecutor);
	this.mailboxProcessor.initMetric(environment.getMetricGroup());
	this.mainMailboxExecutor = mailboxProcessor.getMainMailboxExecutor();
	this.asyncExceptionHandler = new StreamTaskAsyncExceptionHandler(environment);
	this.asyncOperationsThreadPool = Executors.newCachedThreadPool(
		new ExecutorThreadFactory("AsyncOperations", uncaughtExceptionHandler));

	this.stateBackend = createStateBackend();

	this.subtaskCheckpointCoordinator = new SubtaskCheckpointCoordinatorImpl(
		stateBackend.createCheckpointStorage(getEnvironment().getJobID()),
		getName(),
		actionExecutor,
		getCancelables(),
		getAsyncOperationsThreadPool(),
		getEnvironment(),
		this,
		configuration.isUnalignedCheckpointsEnabled(),
		this::prepareInputSnapshot);

	// if the clock is not already set, then assign a default TimeServiceProvider
	if (timerService == null) {
		ThreadFactory timerThreadFactory = new DispatcherThreadFactory(TRIGGER_THREAD_GROUP, "Time Trigger for " + getName());
		this.timerService = new SystemProcessingTimeService(this::handleTimerException, timerThreadFactory);
	} else {
		this.timerService = timerService;
	}

	this.channelIOExecutor = Executors.newSingleThreadExecutor(new ExecutorThreadFactory("channel-state-unspilling"));
}