Fix Deadlock in EventBus post #1493

This commit is contained in:
Joe 2015-06-03 01:56:05 -04:00 committed by md_5
parent 6c4e684de9
commit 918d7229c2

View File

@ -34,10 +34,16 @@ public class EventBus
public void post(Object event) public void post(Object event)
{ {
EventHandlerMethod[] handlers;
lock.readLock().lock(); lock.readLock().lock();
try try
{ {
EventHandlerMethod[] handlers = byEventBaked.get( event.getClass() ); handlers = byEventBaked.get( event.getClass() );
} finally
{
lock.readLock().unlock();
}
if ( handlers != null ) if ( handlers != null )
{ {
for ( EventHandlerMethod method : handlers ) for ( EventHandlerMethod method : handlers )
@ -57,10 +63,6 @@ public class EventBus
} }
} }
} }
} finally
{
lock.readLock().unlock();
}
} }
private Map<Class<?>, Map<Byte, Set<Method>>> findHandlers(Object listener) private Map<Class<?>, Map<Byte, Set<Method>>> findHandlers(Object listener)