在设计可供多个线程使用的单例类时,我遇到了以下挑战:
有一个主线程和另一个称为客户端的线程.主要方法首先获取一个实例,然后客户端也获取实例.然后客户端执行单例类的方法,我的调试步骤向我显示主线程被中断以执行客户端调用的方法.
如何确保客户端线程执行该方法,而不会中断主线程.
提前感谢您的努力.
干杯鲍勃
编辑:
public class SingletonEsperEngine {
private static SingletonEsperEngine esperEngineObject;
//Configuration for the Esper Engine
private static Configuration cepConfig;
//EPSServiceProvider represents the engine instance
private static EPServiceProvider cep;
private static EPRuntime cepRT;
private static EPAdministrator cepAdm;
private static boolean IsAlreadyInitialized;
private static boolean IsNodeIdAvailable;
public static ArrayList<EPStatement> cepStatement;
public static ArrayList<EPStatement> cepLogInfo;
public static ArrayList<EPStatement> cepFilterStatement;
public static HashMap<String, Integer> mStatistics;
public static HashMap<Integer, Integer> mNodeIds;
//Experiment instantions
private static JoinDebug joinDebugExperiment;
private SingletonEsperEngine() {
} …Run Code Online (Sandbox Code Playgroud)