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

com.peterphi.std.threading.ThreadRenameCallableWrap Maven / Gradle / Ivy

There is a newer version: 10.1.5
Show newest version
package com.peterphi.std.threading;

import java.util.concurrent.Callable;

/**
 * Created by bmcleod on 06/09/2016.
 */
public class ThreadRenameCallableWrap implements Callable
{

	final Callable wrappedCall;
	final String threadName;

	public ThreadRenameCallableWrap(String threadName, Callable callable)
	{
		this.wrappedCall = callable;
		this.threadName = threadName;
	}


	@Override
	public V call() throws Exception
	{
		final String originalName = Thread.currentThread().getName();
		Thread.currentThread().setName(threadName);
		try
		{
			return wrappedCall.call();
		}
		finally
		{
			Thread.currentThread().setName(originalName);
		}
	}
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy