首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在JINI中实现TransactionManager

在JINI中实现TransactionManager
EN

Stack Overflow用户
提问于 2012-07-02 02:32:09
回答 1查看 133关注 0票数 0

我正在使用JINI实现两阶段锁。我已经通过遵循算法定义做到了这一点。在我的实现中,我使用一些ArrayLists和HashMap来跟踪哪些参与者已经提交或中止了事务。

每次我执行join/commit/abort操作时,我的ArrayLists和HashMap都是空的(没有以前的参与者),并且我的TransactionManager的HashCode总是不同的。我花了两天时间寻找一个问题,但仍然不能理解为什么会发生这种情况。

代码语言:javascript
复制
// 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

代码语言:javascript
复制
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() ); 

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-02 09:40:43

我能够通过改变这个来解决这个问题:

代码语言:javascript
复制
new JoinManager(this, entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() ); 

要这样做:

代码语言:javascript
复制
new JoinManager(RemoteObject.toStub(this), entries, (ServiceIDListener)null, lookupDiscoveryManager, new LeaseRenewalManager() );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11284626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档