Return-Path: X-Original-To: apmail-hadoop-hdfs-user-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ADF8D1844D for ; Thu, 28 May 2015 21:07:24 +0000 (UTC) Received: (qmail 68092 invoked by uid 500); 28 May 2015 21:07:02 -0000 Delivered-To: apmail-hadoop-hdfs-user-archive@hadoop.apache.org Received: (qmail 67944 invoked by uid 500); 28 May 2015 21:07:01 -0000 Mailing-List: contact user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hadoop.apache.org Delivered-To: mailing list user@hadoop.apache.org Received: (qmail 67934 invoked by uid 99); 28 May 2015 21:07:01 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 May 2015 21:07:01 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 3B74AC0F5C for ; Thu, 28 May 2015 21:07:01 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.879 X-Spam-Level: ** X-Spam-Status: No, score=2.879 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id O0CbCYuU0pNZ for ; Thu, 28 May 2015 21:07:00 +0000 (UTC) Received: from mail-ig0-f180.google.com (mail-ig0-f180.google.com [209.85.213.180]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id E7BAF201E9 for ; Thu, 28 May 2015 21:06:59 +0000 (UTC) Received: by igbhj9 with SMTP id hj9so206002igb.1 for ; Thu, 28 May 2015 14:06:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=GbkPk7oFcGKpSKc4CqTegY+daO92YH7eVS6U/rwhHB0=; b=g92RwEZxRWchAXdo8yi5lJ40YGcp3e6hYRM0XqUhwnN8x1HfnuRHLhvdyZbxzlJZ/Y d2VfHqOh8I9Bce5vKSB85YR5PLham9lbLwGSz7lK+qYzi+3BjpgbUkdQQsremATwVP6S 3BEzX19TcnxVx1YcEdHF7qDGxiq/3Lej89nfsn03HGee/LO7wUc7fQ521kq3x04a77Cx KOPzn3DzXgpWdNKNv8rU0Q3TFYo7Tl+x+qG/lsEiTX1TBFhzVF1b0aqxZyhNgjm138ou +mX16sJgWTpaEkz8r7sMTfCpK4R0ZjoEvXhWKY40vTZ/Zks7wnsvwfoJn/io4Hg+2SMh HBmw== MIME-Version: 1.0 X-Received: by 10.43.116.196 with SMTP id fj4mr11565599icc.38.1432847219393; Thu, 28 May 2015 14:06:59 -0700 (PDT) Received: by 10.107.62.10 with HTTP; Thu, 28 May 2015 14:06:59 -0700 (PDT) Date: Thu, 28 May 2015 14:06:59 -0700 Message-ID: Subject: Question about avoiding reflection with isolated class loader From: Guozhang Wang To: user@hadoop.apache.org Content-Type: multipart/alternative; boundary=bcaec5171bc9878c3b05172abd37 --bcaec5171bc9878c3b05172abd37 Content-Type: text/plain; charset=UTF-8 Hi, I have a question that is probably related to MAPREDUCE-1700 / 5751 / 5957 . Basically I have also encountered the issue that with separate classloaders while developing a programming framework where I have to use reflection inside the application code. To simply the question, let's say my framework code depends on a jar with an older version and the application code depends on the same jar with a newer version (for example Avro 1.4 and 1.7). And let's say that jar has a class named CommonClass. I used a customized post-delegation class loader like Hadoop does so that these two version can exist separately into separate class loader. And if I do sth. like: public static void main(String arg[]) throws Exception { // Say this is framework code new CommonClass().printJarVersion(); // Set the customized class loader as thread context class loader Thread thread = Thread.currentThread(); ClassLoader oldClassLoader = thread.getContextClassLoader(); File appJar = new File("/dir/to/app/class/path"); URL[] classpath = new URL[] { appJar.toURI().toURL() }; PostDelegationClassLoader newClassLoader = new PostDelegationClassLoader(classpath); thread.setContextClassLoader(newClassLoader); try { // Say this is application code, like process(). new CommonClass().printJarVersion(); thread.getContextClassLoader().loadClass("CommonClass").newInstance().printJarVersion(); } finally { thread.setContextClassLoader(oldClassLoader); } } ----------------------- It will print: CommonClass: version 1 CommonClass: version 1 CommonClass: version 2 As one can see I have to use reflection to explicitly specify the customized class loader if I want to create the class with the new version. This is definitely bad for the users. I saw there are some discussions around 1700 and am wondering how Hadoop resolved this issue? Any help is greatly appreciated. -- Guozhang --bcaec5171bc9878c3b05172abd37 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

--bcaec5171bc9878c3b05172abd37--