javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-66

Possible optimization regarding execution of PhaseListeners

    Details

    • Issuezilla Id:
      66

      Description

      Jakob Hookom wrote

      JH> Also, I'm wondering if synchornization blocks around the listeners
      JH> are required? If a phase listener takes 2 seconds to process under
      JH> some condition, it will have the whole application locked for 2
      JH> seconds for everyone. I might need to revist my Java in a Nutshell
      JH> book...

      JH> The result of the changes below would allow phases to be added, but
      JH> would not show up until the NEXT phase. That might be a negative,
      JH> but it would help avoid possibly lengthy synchronization blocks.

      JH> public void addPhaseListener(PhaseListener listener) {
      JH> // .......
      JH> synchronized (listeners)

      { JH> ArrayList temp = (ArrayList)listeners.clone(); JH> temp.add(listener); JH> listeners = temp; JH> }

      JH> // .......
      JH> }
      JH>
      JH> public void removePhaseListener(PhaseListener listener) {
      JH> // .......
      JH> synchronized (listeners)

      { JH> ArrayList temp = (ArrayList) listeners.clone(); JH> temp.remove(listener); JH> listeners = temp; JH> }

      JH> // .......
      JH> }
      JH>

      JH> When you actually execute, just get yourself a pointer to
      JH> 'listeners' so if the pointer changes for 'listeners', we still have
      JH> reference to the original list for this threads execution.

      JH> // grab our reference to the current list in memory
      JH> List ourListeners = listeners;
      JH>
      JH> // Notify the "beforePhase" method of listeners
      JH> if (ourListeners.size() > 0) {
      JH> // declare references BEFORE loops for speed
      JH> PhaseListener listener = null;
      JH> PhaseId listenerPhaseId = null;
      JH> PhaseEvent event = new PhaseEvent(context, phaseId, this);
      JH>
      JH> for (i = 0; i < ourListeners.size(); i++) {
      JH> listener = (PhaseListener) ourListeners.get;
      JH> listenerPhaseId = listener.getPhaseId();
      JH> if (phaseId.equals(listenerPhaseId) ||
      JH> PhaseId.ANY_PHASE.equals(listenerPhaseId)) {
      JH> try

      { JH> listener.beforePhase(event); JH> }

      JH> catch (Throwable e)

      { JH> // do logging JH> }

      JH> }
      JH> }
      JH> }
      JH>
      JH> try {
      JH> if (!skipping(phaseId, context)

      { JH> phase.execute(context); JH> }

      JH> }
      JH> finally {
      JH> if (ourListeners.size() > 0) {
      JH> // declare references BEFORE loops for speed
      JH> PhaseListener listener = null;
      JH> PhaseId listenerPhaseId = null;
      JH> PhaseEvent event = new PhaseEvent(context, phaseId, this);
      JH>
      JH> for (i = 0; i < ourListeners.size(); i++) {
      JH> listener = (PhaseListener) ourListeners.get;
      JH> listenerPhaseId = listener.getPhaseId();
      JH> if (phaseId.equals(listenerPhaseId) ||
      JH> PhaseId.ANY_PHASE.equals(listenerPhaseId)) {
      JH> try

      { JH> listener.afterPhase(event); JH> }

      JH> catch (Throwable e)

      { JH> // do logging JH> }


      JH> }
      JH> }
      JH> }
      JH> }

      1. LifecycleImpl.java
        10 kB
        jhook
      2. LifecycleImpl.java
        10 kB
        jhook
      3. TestLifecycleImpl.java
        14 kB
        jhook

        Activity

        Hide
        Ryan Lubke added a comment -

        Reassign to rlubke.

        Show
        Ryan Lubke added a comment - Reassign to rlubke.
        Hide
        Ryan Lubke added a comment -

        accepted

        Show
        Ryan Lubke added a comment - accepted
        Hide
        Ryan Lubke added a comment -

        Increase to P2. Scalability impact.

        Show
        Ryan Lubke added a comment - Increase to P2. Scalability impact.
        Hide
        Ryan Lubke added a comment -

        Feature backported to 1.1_02

        Show
        Ryan Lubke added a comment - Feature backported to 1.1_02
        Hide
        Manfred Riem added a comment -

        Closing issue out

        Show
        Manfred Riem added a comment - Closing issue out

          People

          • Assignee:
            Ryan Lubke
            Reporter:
            Ed Burns
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: