1.想在运行时抛出异常,终止方法的运行
private final Set<Long> THREADS = new HashSet<>();

public void someMethod () {
if (THREADS.contains(Thread.currentThread().getId())) {
throw new RuntimeException("该线程不能再调用这个方法");
}
THREADS.add(Thread.currentThread().getId()); // 方法内容
}
2.不想抛出异常,只想运行一次,并不影响其他方法的调用
public static void systemInit(){
if (!THREADS.contains(Thread.currentThread().getId())) {
NativeLibrary.addSearchPath("libcommon-0", System.getenv("SKYEYEBIN"));
CLibrary.INSTANCE.SIM_init();
}
THREADS.add(Thread.currentThread().getId());
}
05-11 15:02