Return-Path: X-Original-To: apmail-hadoop-common-issues-archive@minotaur.apache.org Delivered-To: apmail-hadoop-common-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F13E310B61 for ; Mon, 28 Oct 2013 08:08:48 +0000 (UTC) Received: (qmail 83113 invoked by uid 500); 28 Oct 2013 08:08:44 -0000 Delivered-To: apmail-hadoop-common-issues-archive@hadoop.apache.org Received: (qmail 82934 invoked by uid 500); 28 Oct 2013 08:08:35 -0000 Mailing-List: contact common-issues-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-issues@hadoop.apache.org Delivered-To: mailing list common-issues@hadoop.apache.org Received: (qmail 82878 invoked by uid 99); 28 Oct 2013 08:08:30 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Oct 2013 08:08:30 +0000 Date: Mon, 28 Oct 2013 08:08:30 +0000 (UTC) From: "Joe Au (JIRA)" To: common-issues@hadoop.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (HADOOP-10063) RunJar ClassLoader cached the class can't release MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HADOOP-10063?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Joe Au updated HADOOP-10063: ---------------------------- Description: At the end of method main() {code:title=RunJar.java|borderStyle=solid} ClassLoader loader = new URLClassLoader(classPath.toArray(new URL[0])); Thread.currentThread().setContextClassLoader(loader); Class mainClass = Class.forName(mainClassName, true, loader); Method main = mainClass.getMethod("main", new Class[] { Array.newInstance(String.class, 0).getClass() }); String[] newArgs = Arrays.asList(args) .subList(firstArg, args.length).toArray(new String[0]); try { main.invoke(null, new Object[] { newArgs }); } catch (InvocationTargetException e) { throw e.getTargetException(); } {code} The ClassLoader cached the class can't release.Because the development time class code will often changes, so will be very inconvenient. Rewrite as follows: {code:title=RunJar.java|borderStyle=solid} ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); ClassLoader loader = new URLClassLoader(classPath.toArray(new URL[0]), prevCl); try { Thread.currentThread().setContextClassLoader(loader); Class mainClass = Class.forName(mainClassName, true, loader); Method main = mainClass.getMethod("main", new Class[] { Array .newInstance(String.class, 0).getClass() }); String[] newArgs = Arrays.asList(args).subList(firstArg, args.length) .toArray(new String[0]); main.invoke(null, new Object[] { newArgs }); } catch (InvocationTargetException e) { throw e.getTargetException(); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } {code} was: At the end of method main() {code:title=RunJar.java|borderStyle=solid} ClassLoader loader = new URLClassLoader(classPath.toArray(new URL[0])); Thread.currentThread().setContextClassLoader(loader); Class mainClass = Class.forName(mainClassName, true, loader); Method main = mainClass.getMethod("main", new Class[] { Array.newInstance(String.class, 0).getClass() }); String[] newArgs = Arrays.asList(args) .subList(firstArg, args.length).toArray(new String[0]); try { main.invoke(null, new Object[] { newArgs }); } catch (InvocationTargetException e) { throw e.getTargetException(); } {code} The ClassLoader cached the class can't release.Because the development time code will often changes, so will be very inconvenient. Rewrite as follows: {code:title=RunJar.java|borderStyle=solid} ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); ClassLoader loader = new URLClassLoader(classPath.toArray(new URL[0]), prevCl); try { Thread.currentThread().setContextClassLoader(loader); Class mainClass = Class.forName(mainClassName, true, loader); Method main = mainClass.getMethod("main", new Class[] { Array .newInstance(String.class, 0).getClass() }); String[] newArgs = Arrays.asList(args).subList(firstArg, args.length) .toArray(new String[0]); main.invoke(null, new Object[] { newArgs }); } catch (InvocationTargetException e) { throw e.getTargetException(); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } {code} > RunJar ClassLoader cached the class can't release > ------------------------------------------------- > > Key: HADOOP-10063 > URL: https://issues.apache.org/jira/browse/HADOOP-10063 > Project: Hadoop Common > Issue Type: Bug > Components: util > Affects Versions: 1.0.3, 2.2.0 > Reporter: Joe Au > > At the end of method main() > {code:title=RunJar.java|borderStyle=solid} > ClassLoader loader = > new URLClassLoader(classPath.toArray(new URL[0])); > Thread.currentThread().setContextClassLoader(loader); > Class mainClass = Class.forName(mainClassName, true, loader); > Method main = mainClass.getMethod("main", new Class[] { > Array.newInstance(String.class, 0).getClass() > }); > String[] newArgs = Arrays.asList(args) > .subList(firstArg, args.length).toArray(new String[0]); > try { > main.invoke(null, new Object[] { newArgs }); > } catch (InvocationTargetException e) { > throw e.getTargetException(); > } > {code} > The ClassLoader cached the class can't release.Because the development time class code will often changes, so will be very inconvenient. > Rewrite as follows: > {code:title=RunJar.java|borderStyle=solid} > ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); > ClassLoader loader = new URLClassLoader(classPath.toArray(new URL[0]), prevCl); > try { > Thread.currentThread().setContextClassLoader(loader); > Class mainClass = Class.forName(mainClassName, true, loader); > Method main = mainClass.getMethod("main", new Class[] { Array > .newInstance(String.class, 0).getClass() }); > String[] newArgs = Arrays.asList(args).subList(firstArg, args.length) > .toArray(new String[0]); > > main.invoke(null, new Object[] { newArgs }); > } catch (InvocationTargetException e) { > throw e.getTargetException(); > } finally { > // Restore > Thread.currentThread().setContextClassLoader(prevCl); > } > {code} -- This message was sent by Atlassian JIRA (v6.1#6144)