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

cn.fantasticmao.mundo.data.partition.PartitionSeedContext Maven / Gradle / Ivy

There is a newer version: 1.0.10
Show newest version
package cn.fantasticmao.mundo.data.partition;

import java.util.Stack;

/**
 * 使用 {@link java.lang.ThreadLocal} 管理 {@link PartitionParam} 参数生成的 PartitionSeed。
 *
 * @author fantasticmao
 * @version 1.0
 * @since 2017/11/16
 */
public class PartitionSeedContext {
    private static final ThreadLocal> SEED_STACK = ThreadLocal.withInitial(Stack::new);

    public static Object push(Object seed) {
        return SEED_STACK.get().push(seed);
    }

    public static Object pop() {
        Stack stack = SEED_STACK.get();
        return !stack.empty() ? stack.pop() : null;
    }

    public static void clear() {
        PartitionSeedContext.SEED_STACK.remove();
    }
}