Пример #1
1
  private static void showThreads(PrintStream pw, ThreadGroup g, Thread current) {
    int nthreads = g.activeCount();
    pw.println("\nThread Group = " + g.getName() + " activeCount= " + nthreads);
    Thread[] tarray = new Thread[nthreads];
    int n = g.enumerate(tarray, false);

    for (int i = 0; i < n; i++) {
      Thread thread = tarray[i];
      ClassLoader loader = thread.getContextClassLoader();
      String loaderName = (loader == null) ? "Default" : loader.getClass().getName();
      Thread.State state = thread.getState();
      long id = thread.getId();
      pw.print("   " + id + " " + thread.getName() + " " + state + " " + loaderName);
      if (thread == current) pw.println(" **** CURRENT ***");
      else pw.println();
    }

    int ngroups = g.activeGroupCount();
    ThreadGroup[] garray = new ThreadGroup[ngroups];
    int ng = g.enumerate(garray, false);
    for (int i = 0; i < ng; i++) {
      ThreadGroup nested = garray[i];
      showThreads(pw, nested, current);
    }
  }
Пример #2
1
  /**
   * Load the class with the specified name, searching using the following algorithm until it finds
   * and returns the class. If the class cannot be found, returns <code>ClassNotFoundException
   * </code>.
   *
   * <ul>
   *   <li>Call <code>findLoadedClass(String)</code> to check if the class has already been loaded.
   *       If it has, the same <code>Class</code> object is returned.
   *   <li>If the <code>delegate</code> property is set to <code>true</code>, call the <code>
   *       loadClass()</code> method of the parent class loader, if any.
   *   <li>Call <code>findClass()</code> to find this class in our locally defined repositories.
   *   <li>Call the <code>loadClass()</code> method of our parent class loader, if any.
   * </ul>
   *
   * If the class was found using the above steps, and the <code>resolve</code> flag is <code>true
   * </code>, this method will then call <code>resolveClass(Class)</code> on the resulting Class
   * object.
   *
   * @param name Name of the class to be loaded
   * @param resolve If <code>true</code> then resolve the class
   * @exception ClassNotFoundException if the class was not found
   */
  public Class loadClass(String name, boolean resolve) throws ClassNotFoundException {

    Class clazz = null;

    // (0) Check our previously loaded class cache
    clazz = findLoadedClass(name);
    if (clazz != null) {
      if (resolve) resolveClass(clazz);
      return (clazz);
    }

    // (.5) Permission to access this class when using a SecurityManager
    int dot = name.lastIndexOf('.');
    if (System.getSecurityManager() != null) {
      if (dot >= 0) {
        try {
          securityManager.checkPackageAccess(name.substring(0, dot));
        } catch (SecurityException se) {
          String error = "Security Violation, attempt to use " + "Restricted Class: " + name;
          System.out.println(error);
          throw new ClassNotFoundException(error);
        }
      }
    }

    // Class is in a package, delegate to thread context class loader
    if (!name.startsWith(Constants.JSP_PACKAGE_NAME)) {
      ClassLoader classLoader = null;
      if (System.getSecurityManager() != null) {
        classLoader = (ClassLoader) AccessController.doPrivileged(privLoadClass);
      } else {
        classLoader = Thread.currentThread().getContextClassLoader();
      }
      clazz = classLoader.loadClass(name);
      if (resolve) resolveClass(clazz);
      return clazz;
    }

    // Only load classes for this JSP page
    if (name.startsWith(className)) {
      String classFile = name.substring(Constants.JSP_PACKAGE_NAME.length() + 1) + ".class";
      byte[] cdata = loadClassDataFromFile(classFile);
      if (cdata == null) throw new ClassNotFoundException(name);
      if (System.getSecurityManager() != null) {
        ProtectionDomain pd = new ProtectionDomain(codeSource, permissionCollection);
        clazz = defineClass(name, cdata, 0, cdata.length, pd);
      } else {
        clazz = defineClass(name, cdata, 0, cdata.length);
      }
      if (clazz != null) {
        if (resolve) resolveClass(clazz);
        return clazz;
      }
    }

    throw new ClassNotFoundException(name);
  }
Пример #3
0
 private static synchronized String getJavascript() {
   if (jstext == null) {
     InputStream istr = null;
     try {
       ClassLoader loader = Thread.currentThread().getContextClassLoader();
       istr = loader.getResourceAsStream(JAVASCRIPT_RESOURCE);
       jstext = StringUtil.fromInputStream(istr);
       istr.close();
     } catch (Exception e) {
       log.error("Can't load javascript", e);
     } finally {
       IOUtil.safeClose(istr);
     }
   }
   return jstext;
 }