/**
 * The MIT License
 *
 * Copyright (C) 2015 Asterios Raptis
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package de.alpharogroup.lang.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import lombok.experimental.UtilityClass;

/**
 * The class {@link ThreadExtensions}.
 */
@UtilityClass
public final class ThreadExtensions
{

	/**
	 * Finds all threads the are currently running.
	 *
	 * @return An array with all threads the are currently running.
	 */
	public static Thread[] resolveRunningThreads()
	{
		final Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
		final Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);
		return threadArray;
	}

	/**
	 * Finds all threads the are currently running and converts them to {@link ThreadDataBean} and
	 * puts them to a {@link List} that is returned.
	 *
	 * @return the new {@link List}
	 */
	public static List<ThreadDataBean> newThreadData()
	{
		final Thread[] thread = resolveRunningThreads();
		final List<ThreadDataBean> snapshotOfThreadDataBeans = new ArrayList<>(thread.length);
		for (int i = 0; i < thread.length; i++)
		{
			final Thread t = thread[i];
			snapshotOfThreadDataBeans.add(ThreadDataBean.of(t));
		}
		return snapshotOfThreadDataBeans;
	}

}

@@ -1254,150 +1254,2117 @@
 et;%0A
-%0Aimport lombok.experimental.UtilityClass;%0A%0A/**%0A * The class %7B@link ThreadExtensions%7D.%0A */%0A@UtilityClass%0Apublic final class ThreadExtensions%0A%7B%0A
+import java.util.concurrent.Callable;%0Aimport java.util.concurrent.CompletableFuture;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.ForkJoinPool;%0Aimport java.util.function.Supplier;%0A%0Aimport lombok.experimental.UtilityClass;%0A%0A/**%0A * The class %7B@link ThreadExtensions%7D.%0A */%0A@UtilityClass%0Apublic final class ThreadExtensions%0A%7B%0A%0A    /**%0A     * Creates a custom thread pool that are executed in parallel processes with the given number of the cpu cores%0A     * @param task the %7B@link Callable%7D task to execute%0A     * @param cpuCores the number of the cpu cores to run with%0A     * @param %3CT%3E the generic type of the result%0A     * @return the result of the given task%0A     * @throws ExecutionException if the computation threw an%0A     * exception%0A     * @throws InterruptedException if the current thread is not a%0A     * member of a ForkJoinPool and was interrupted while waiting%0A     */%0A    public static %3CT%3E T runCallableWithCpuCores(Callable%3CT%3E task, int cpuCores) throws ExecutionException, InterruptedException %7B%0A        ForkJoinPool forkJoinPool = new ForkJoinPool(cpuCores);%0A        return forkJoinPool.submit(task).get();%0A    %7D%0A%0A    /**%0A     * Creates a custom thread pool that are executed in parallel processes with the will run with the given number of the cpu cores%0A     * @param supplier the %7B@link Supplier%7D task to execute%0A     * @param cpuCores the number of the cpu cores to run with%0A     * @param %3CT%3E the generic type of the result%0A     * @return the result of the given task%0A     * @throws ExecutionException if the computation threw an%0A     * exception%0A     * @throws InterruptedException if the current thread is not a%0A     * member of a ForkJoinPool and was interrupted while waiting%0A     */%0A    public static %3CT%3E T runAsyncSupplierWithCpuCores(Supplier%3CT%3E supplier, int cpuCores) throws ExecutionException, InterruptedException %7B%0A        ForkJoinPool forkJoinPool = new ForkJoinPool(cpuCores);%0A        CompletableFuture%3CT%3E future = CompletableFuture.supplyAsync(%0A                supplier,%0A                forkJoinPool%0A        );%0A        return future.get();%0A    %7D%0A%09
 %0A%09/*

Update ThreadExtensions.java