小编den*_*ced的帖子

有几个线程可以在同一个对象上等待吗?

我有一个jstack转储,似乎说几个线程已经获得了对同一个对象的锁定.据我所知,这是不可能的,但是不是吗?

这是在try块中进行关键等待调用的代码:

protected boolean waitMaxWaitingTime(UserInfo aUserInfo) throws EventServiceException {
    final int theMaxWaitingTime = myConfiguration.getMaxWaitingTime();
    if(theMaxWaitingTime <= 0) {
        return true;
    }
    if(aUserInfo.isEventsEmpty()) {
        //monitor for event notification and double checked
        synchronized(aUserInfo) {
            if(aUserInfo.isEventsEmpty()) {
                try {
                    final long theStartTime = System.currentTimeMillis();
                    // --- THE CRUCIAL WAIT CALL ---
                    aUserInfo.wait(theMaxWaitingTime);
                    return (System.currentTimeMillis() - theStartTime >= theMaxWaitingTime);
                } catch(InterruptedException e) {
                    throw new EventServiceException("Error on waiting max. waiting time!", e);
                }
            }
        }
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

这是jstack转储(有选择地):

"thread-79" #161 daemon prio=5 …
Run Code Online (Sandbox Code Playgroud)

java multithreading

5
推荐指数
2
解决办法
609
查看次数

放置外部虚拟表

大型C++软件设计(Lakos),第652页:

问题是,"编译器在哪个唯一的翻译单元中存放给定类的虚拟表定义?".CFRONT(以及许多其他C++实现)采用的技巧是将外部虚拟表放置在翻译单元中,该单元定义类中出现的词法上第一个非内联函数(如果存在).

最常用的编译器(GCC和Visual C++)仍然是这种情况吗?还是曾经?

c++ gcc compilation vtable visual-c++

4
推荐指数
1
解决办法
1400
查看次数

标签 统计

c++ ×1

compilation ×1

gcc ×1

java ×1

multithreading ×1

visual-c++ ×1

vtable ×1