public abstract class AbstractEsOperate<T extends BaseEsIndexModel> {
private final ThreadLocal<T> threadLocalT = new ThreadLocal<>();
private final ThreadLocal<Type> threadLocalType = new ThreadLocal<>();
return threadLocalT.get();
protected Type getType() {
return threadLocalType.get();
private final Class<T> clazz;
// Constructor to accept the Class<T> type
protected AbstractEsOperate(Class<T> clazz) {
private Boolean check() {
return clazz.equals(threadLocalT.get().getClass());
private void init(T t, Type type) {
threadLocalType.set(type);
protected abstract Boolean exec();
public void doBusiness(T t, Type type) {
threadLocalType.remove();