我正在使用 JINI 实现两相锁。我已经按照算法定义完成了它。在我的实现中,我有一些 ArrayLists 和 HashMap 来跟踪哪些参与者已经提交或中止了事务。
每次我执行加入/提交/中止操作时,我的 ArrayLists 和 HashMap 都是空的(没有以前的参与者),并且我的 TransactionManager 的 HashCode 总是不同的。我花了 2 天时间寻找问题,但仍然无法理解为什么会这样。
// here is the implementation of join method of my TransactionManager
private HashMap<Long, ArrayList<TransactionParticipant>> _transactions = new HashMap<Long, ArrayList<TransactionParticipant>>();
private ArrayList<TransactionParticipant> _participantTest = new ArrayList<TransactionParticipant>();
@Override
public synchronized void join(long trxId, TransactionParticipant tp, long crashCount) throws UnknownTransactionException, CannotJoinException, CrashCountException, RemoteException {
// add new participant to list of participants that belong to current trxId
List<TransactionParticipant> participants = _transactions.get(trxId);
_participantTest.add(tp);
participants.add(tp);
System.out.println("Test hash code " + this.hashCode());
System.out.println("Number of participants is " + participants.size() + "for Trxid " + trxId);
System.out.println("Number of participants in other is " + _participantTest.size() + "for Trxid " + trxId);
}
以下代码用于“发布”我的 TransactionManager
String[] groups = { "group" };
ServiceInfo serviceInfo = new ServiceInfo(
"twoPhaseTrxManager",
"a",
"b",
"1.0",
"Join Manager",
"c");
Entry[] entries = new Entry[] { serviceInfo };
LookupDiscoveryManager lookupDiscoveryManager = new LookupDiscoveryManager(groups, null, null);
// "this" (first argument) refers to Current instance of transaction manager (object being published)
new JoinManager(this, entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() );
任何帮助都非常感谢。