我正在使用JINI实现两阶段锁。我已经通过遵循算法定义做到了这一点。在我的实现中,我使用一些ArrayLists和HashMap来跟踪哪些参与者已经提交或中止了事务。
每次我执行join/commit/abort操作时,我的ArrayLists和HashMap都是空的(没有以前的参与者),并且我的TransactionManager的HashCode总是不同的。我花了两天时间寻找一个问题,但仍然不能理解为什么会发生这种情况。
// 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() ); 任何帮助都是非常感谢的。
发布于 2012-07-02 09:40:43
我能够通过改变这个来解决这个问题:
new JoinManager(this, entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() ); 要这样做:
new JoinManager(RemoteObject.toStub(this), entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() );https://stackoverflow.com/questions/11284626
复制相似问题