我必须编写一个托管在包含两个服务器的WebLogic 12c集群上的EJB。 程序必须是单线程的,因此两个服务器不能同时运行该代码。
除了编写自定义令牌系统之外,还有办法将我的EJB配置为整个集群的单线程吗?
编辑:这是我提到“自定义令牌系统”时我想到的伪代码:
public void myEJBMethod() {
String tokenUUID = getTokenFromDB("IMSToken");
if (tokenUUID != "TokenNotAvailable") {
doMyEJBStuff();
releaseToken("IMSToken", tokenUUID);
}
}
private String getTokenFromDB(String tokenName) {
int tokenQty=0;
String myThreadUUID = java.util.UUID.randomUUID().toString();
INSERT INTO TOKEN_TRACKER (TOKEN_NAME, THREAD_UUID, CREATED_DATE) VALUE ({tokenName}, {myThreadUUID}, new Date());
COMMIT;
tokenQty= SELECT COUNT(*) FROM TOKEN_TRACKER WHERE TOKEN_NAME = {tokenName} AND THREAD_UUID NOT LIKE {myThreadUUID};
if (tokenQty>0) {
logger.trace("Token not available");
releaseToken(tokenName, myThreadUUID);
return "TokenNotAvailable";
}
else {
return myThreadUUID;
}
}
private void releaseToken(String tokenName, String tokenUIID) {
DELETE FROM TOKEN_TRACKER WHERE THREAD_UUID = {myThreadUUID};
COMMIT;
}
答案 0 :(得分:0)
https://developsimpler.blogspot.ca/2012/03/weblogic-clusters-and-singleton-service.html