com.litongjava.tio.utils.thread.TioThreadUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tio-utils Show documentation
Show all versions of tio-utils Show documentation
t-io is a aio framework for java
package com.litongjava.tio.utils.thread;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
* @author Tong Li
*/
public class TioThreadUtils {
private static ExecutorService fixedThreadPool;
static {
fixedThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
}
public static String stackTrace() {
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
StringBuilder buf = new StringBuilder();
for (StackTraceElement element : elements) {
buf.append("\r\n ").append(element.getClassName()).append(".").append(element.getMethodName()).append("(").append(element.getFileName())
.append(":").append(element.getLineNumber()).append(")");
}
return buf.toString();
}
public static ExecutorService getFixedThreadPool() {
return fixedThreadPool;
}
public static Future submit(Callable task) {
return fixedThreadPool.submit(task);
}
public static Future submit(Runnable task, T result) {
return fixedThreadPool.submit(task, result);
}
public static Future> submit(Runnable task) {
return fixedThreadPool.submit(task);
}
}