Return-Path: X-Original-To: apmail-hbase-user-archive@www.apache.org Delivered-To: apmail-hbase-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C352ECFE4 for ; Thu, 20 Mar 2014 09:19:54 +0000 (UTC) Received: (qmail 70512 invoked by uid 500); 20 Mar 2014 09:19:51 -0000 Delivered-To: apmail-hbase-user-archive@hbase.apache.org Received: (qmail 69933 invoked by uid 500); 20 Mar 2014 09:19:49 -0000 Mailing-List: contact user-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hbase.apache.org Delivered-To: mailing list user@hbase.apache.org Received: (qmail 69908 invoked by uid 99); 20 Mar 2014 09:19:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Mar 2014 09:19:47 +0000 X-ASF-Spam-Status: No, hits=-0.1 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of amits@infolinks.com designates 207.126.144.123 as permitted sender) Received: from [207.126.144.123] (HELO mail-ie0-f171.google.com) (207.126.144.123) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 20 Mar 2014 09:19:42 +0000 Received: from mail-ie0-f171.google.com ([209.85.223.171]) (using TLSv1) by eu1sys200aob107.postini.com ([207.126.147.11]) with SMTP ID DSNKUyqymBMmjpf5JyVIH77508XBq2NbQPTQ@postini.com; Thu, 20 Mar 2014 09:19:21 UTC Received: by mail-ie0-f171.google.com with SMTP id ar20so550612iec.16 for ; Thu, 20 Mar 2014 02:19:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=t9IDo4uwuhxFgVxK4zMmnO1xYWldlxDurLxwEMmlxys=; b=IT55xGPULeCvYtZN8u7VIoc97tWlDfZQgAfpZfJTBu4X+X2rNTrBbOoM4nXOd1Ooq8 WB+ZH5H+O2uqWjA/WJQcYEkB02rLhMRtjFLepCBuAOVQ1N4SjjeCxJW1kvNo2QnnJYc6 Z2TPpn3j44pKpIThWiblcaueyulfWEzQGF80zxnQbLENbiQ7/c26fAKq3ov/tYHKt1JV TbTVo+ZxGveJ7DCkcYoX70er+x1hneBVMsQE/gT/QFGSWJXZ0l6iHR1IbyhBwxXDInWz VluH2x60PDts+rDxcdP0gJESRmujomjeYz4K6rdG17veS0Wv+HrKf6qYVxmA9hZDnX5Q MQIg== X-Gm-Message-State: ALoCoQkNwxKOWyghJjAiAikNwYwOv2zkFcMcIR/2JqSWieht0SGhi72FxLUEMrRSHpboOPFeKNJdm9mkE6GXgk9hypolwjxIyDqx1Y/DMBKZU49fU7owuEKMnZxWPTnRAsWSxnlfoR3CVMI/cw+X1Q7cLCXc+J6o/QSdqfZPQ1L4zJdQunhrwms= X-Received: by 10.50.6.9 with SMTP id w9mr1656932igw.1.1395307159854; Thu, 20 Mar 2014 02:19:19 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.50.6.9 with SMTP id w9mr1656919igw.1.1395307159601; Thu, 20 Mar 2014 02:19:19 -0700 (PDT) Received: by 10.64.225.41 with HTTP; Thu, 20 Mar 2014 02:19:19 -0700 (PDT) In-Reply-To: References: Date: Thu, 20 Mar 2014 11:19:19 +0200 Message-ID: Subject: Re: Class loading in Hadoop and HBase From: Amit Sela To: user@hbase.apache.org Content-Type: multipart/alternative; boundary=047d7b874c9099dccf04f50643db X-Virus-Checked: Checked by ClamAV on apache.org --047d7b874c9099dccf04f50643db Content-Type: text/plain; charset=ISO-8859-1 And what's wrong with: ClassLoader cl = Clazz.class.getClassLoader(); On Thu, Mar 20, 2014 at 11:03 AM, haosdent wrote: > > should prefer the Class's CL because the client's application affects the > TCCL. > You could call "Thread.currentThread().setContextClassLoader(classLoader)" > before the classloader load "Configuration" or "HbaseObjectWritable" class. > > You consider the logic below should be better: > ClassLoader cl = Clazz.class.getClassLoader(); > if (cl == null) { > cl = Thread.currentThread().getContextClassLoader(); > } > > But variable "cl" couln't be null here. So the code snippet above is > equivalent to the following code: > > ClassLoader cl = Clazz.class.getClassLoader(); > > > On Thu, Mar 20, 2014 at 4:39 PM, Amit Sela wrote: > > > I understand the benefits of TCCL, but I think, and I would like to hear > > the "why not", that code that may run in the client side (like in the > case > > of Configuration and HbaseObjectWritable examples I gave) should prefer > the > > Class's CL because the client's application affects the TCCL. > > > > > > On Thu, Mar 20, 2014 at 8:56 AM, haosdent wrote: > > > > > Because we could change the value of "Thread.currentThread(). > > > getContextClassLoader()" by > > "Thread.currentThread().setContextClassLoader( > > > classLoader)". But we couldn't change the value of > > > "this.getClass().getClassLoader()". > > > Maybe a little confused, TCCL is more flexible than the class's CL. > > > > > > > > > On Thu, Mar 20, 2014 at 2:43 PM, Amit Sela > wrote: > > > > > > > I understand that. But why ? Why prefer the TCCL over the class's CL > ? > > > > On Mar 20, 2014 3:00 AM, "haosdent" wrote: > > > > > > > > > Sometimes we would use > "Thread.currentThread().setContextClassLoader( > > > > > classLoader);" to specify classloader. So > > > > > "Thread.currentThread().getContextClassLoader();" > > > > > should be the first choice. > > > > > > > > > > > > > > > On Thu, Mar 20, 2014 at 1:53 AM, Amit Sela > > > wrote: > > > > > > > > > > > Hi all, > > > > > > I'm running with Hadoop 1.0.4 and HBase 0.94.12 bundled (OSGi) > > > > versions I > > > > > > built. > > > > > > Most issues I encountered are related to class loaders. > > > > > > > > > > > > One of the patterns I noticed in both projects is: > > > > > > > > > > > > ClassLoader cl = > > Thread.currentThread().getContextClassLoader(); > > > > > > if(cl == null) { > > > > > > cl = Clazz.class.getClassLoader(); > > > > > > } > > > > > > > > > > > > Where Clazz is the Class containing this code. > > > > > > > > > > > > I was wondering about this choice... Why not go the other way > > around: > > > > > > > > > > > > ClassLoader cl = Clazz.class.getClassLoader(); > > > > > > if(cl == null) { > > > > > > cl = Thread.currentThread().getContextClassLoader(); > > > > > > } > > > > > > > > > > > > And in a more general note, why not always use Configuration (and > > let > > > > > it's > > > > > > cl be this.getClass().getClassLoader()) to load classes ? > > > > > > > > > > > > That would surely help in integration with modularity frameworks. > > > > > > > > > > > > Thanks, > > > > > > Amit. > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > Best Regards, > > > > > Haosdent Huang > > > > > > > > > > > > > > > > > > > > > -- > > > Best Regards, > > > Haosdent Huang > > > > > > > > > -- > Best Regards, > Haosdent Huang > --047d7b874c9099dccf04f50643db--