Commons Logging
  1. Commons Logging
  2. LOGGING-37

[logging] LogFactory#getLogFactory should not look for method every time

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.4
    • Fix Version/s: 1.2
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      LogFactory checks for the existence of Thread#getContextClassLoader every time
      #getLogFactory is invoked and does a reflective invocation. This is
      unnecessarily expensive if many Log objects are created. An easy patch is to
      remember the Method object; the lookup happens only once and it will massively
      profit from reflection optimizations after a number of calls (a Java code stub
      is generated by the reflection package).

      Patch:

      419a420,426
      > private static Method GET_CONTEXT_CLASS_LOADER = null;
      > static {
      > try

      { > GET_CONTEXT_CLASS_LOADER = Thread.class.getMethod("getContextClassLoad er", null); > }

      catch (NoSuchMethodException e)

      { > }

      > }
      436,439c443
      < try {
      < // Are we running on a JDK 1.2 or later system?
      < Method method = Thread.class.getMethod("getContextClassLoader", nu
      ll);
      <

      > if(GET_CONTEXT_CLASS_LOADER != null)

      { 442c446 < classLoader = (ClassLoader)method.invoke(Thread.currentThread( ), null); --- > classLoader = (ClassLoader)GET_CONTEXT_CLASS_LOADER.invoke(Thr ead.currentThread(), null); 472c476 < }

      catch (NoSuchMethodException e)

      { --- > }

      else {

        Activity

        Matthias Ernst created issue -
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 38626 12342905
        Henri Yandell made changes -
        Project Commons [ 12310458 ] Commons Logging [ 12310484 ]
        Key COM-2753 LOGGING-37
        Affects Version/s 1.0.4 [ 12311678 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Component/s Logging [ 12311124 ]
        Henri Yandell made changes -
        Affects Version/s 1.0.4 [ 12311713 ]
        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Thomas Neidhart made changes -
        Resolution Won't Fix [ 2 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Thomas Neidhart made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Fix Version/s 1.2 [ 12327167 ]
        Resolution Fixed [ 1 ]
        Thomas Neidhart made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Matthias Ernst
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development