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,),以后会过期