All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.portal.background.task.internal.BackgroundTaskInExecutionUtil Maven / Gradle / Ivy

There is a newer version: 7.0.63
Show newest version
/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

package com.liferay.portal.background.task.internal;

import com.liferay.petra.lang.SafeCloseable;

import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Dante Wang
 */
public class BackgroundTaskInExecutionUtil {

	public static boolean isInExecution(long backgroundTaskId) {
		return _backgroundTaskIds.contains(backgroundTaskId);
	}

	public static SafeCloseable setInExecutionWithSafeCloseable(
		long backgroundTaskId) {

		_backgroundTaskIds.add(backgroundTaskId);

		return () -> _backgroundTaskIds.remove(backgroundTaskId);
	}

	private static final Set _backgroundTaskIds =
		Collections.newSetFromMap(new ConcurrentHashMap<>());

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy