hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Au (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HADOOP-10063) RunJar ClassLoader cached the class can't release
Date Tue, 22 Oct 2013 10:27:41 GMT

     [ https://issues.apache.org/jira/browse/HADOOP-10063?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Joe Au updated HADOOP-10063:
----------------------------

    Issue Type: Bug  (was: Improvement)

> 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 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)

Mime
View raw message