You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by Bjørn Vidar Remme <bv...@gmail.com> on 2005/11/01 19:23:26 UTC

JS1.6: PortletActionEvent.fireEvent thread safe?

Hi,
  while i was browsing some code in a debug session i noted the following in
PortletActionEvent:
  =====
 /**
* Cache ActionEvent methods to avoid repeated replection
* method lookups.
*/
private static final HashMap eventMethods = new HashMap();
 [CUT]
  protected boolean fireEvent(RunData data, Class deltaClass, Object
deltaValue, String theButton)
{
 [CUT]
String methodKey = getClass().getName()+":"
+theButton+":"+classes[0].getName()
+":"+classes[1].getName();

Method method = (Method)eventMethods.get(methodKey);
if(method == null)
{
method = getClass().getMethod(theButton, classes);
eventMethods.put(methodKey, method);
}

[CUT]
  =====
  Note the static HashMap at the top and the put/get in fireEvent().
 Is it not possible that multiple threads work on this static map at the
same time?
  A HashMap object is not synchronized and according to the JavaDoc:
''' If multiple threads access this map concurrently, and at least one of
the threads modifies the map structurally, it must be synchronized
externally.'''
  - Bjørn Vidar Remme