ReflectionUtil分析

org.apache.hadoop.util.ReflactionUtil

1.内部类CopyInCopyOutBuffer(线程池管理) 结合类SerializationFactory(单例模式管理) 序列化和反序列化copy

 private static class CopyInCopyOutBuffer {
    DataOutputBuffer outBuffer = new DataOutputBuffer();
    DataInputBuffer inBuffer = new DataInputBuffer();
    /**
     * Move the data from the output buffer to the input buffer.
     */
    void moveData() {
      inBuffer.reset(outBuffer.getData(), outBuffer.getLength());
    }
  }

2. getDeclaredFieldsIncludingInherited 与getDeclaredMethodsIncludingInherited 返回该类以及父类的field和method

3.printThreadInfo 打印线程信息

static private ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

long[] threadIds = threadBean.getAllThreadIds();

for (long tid: threadIds) {
      ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH);

....

}

4.ByteArrayOutputStream buffer = new ByteArrayOutputStream();

PrintWriter stream = new PrintWriter(buffer);

stream.println("Process Thread Dump: " + title);

stream.flush();

buffer.toString()

5.从配置文件中创建对象(给定class)

public static <T> T newInstance(Class<T> theClass, Configuration conf) {
    T result;
    try {
      Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass);
      if (meth == null) {
        meth = theClass.getDeclaredConstructor(EMPTY_ARRAY);
        meth.setAccessible(true);
        CONSTRUCTOR_CACHE.put(theClass, meth);
      }
      result = meth.newInstance();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    setConf(result, conf);
    return result;
  }

6.缓存class

private static final Map<Class<?>, Constructor<?>> CONSTRUCTOR_CACHE = 
    new ConcurrentHashMap<Class<?>, Constructor<?>>();

7.setJobConf方法为兼容性保留(mapred)(configure,),以后会过期

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值