跳至主要内容

博文

目前显示的是 十月, 2016的博文

Install `nicstat`on Linux

Introduction nicstat is to network interfaces as “iostat” is to disks, or “prstat” is to processes. It is designed as a much better version of “netstat -i”. Its differences include: Reports bytes in & out as well as packets. Normalizes these values to per-second rates. Reports on all interfaces (while iterating) Reports Utilization (rough calculation as of now) Reports Saturation (also rough) Prefixes statistics with the current time With the help from nicstat , we can identify whether distributed Java application is saturating the network by view the utilization percentage of specific interface. Download Sourceforge Download Link Build Following the guide of README.txt, we build like following: $ mv Makefile.Linux Makefile $ make mv nicstat `./nicstat.sh --bin-name` Install $ make install gcc -O3 -m32 nicstat.c -o nicstat In file included from /usr/include/features.h: 392 : 0 , from /usr/include/stdio.h: 27 , from nicsta...

Java Synthetic Constructor

public class DefaultConstructor { private static class B { } public static void main (String[] args) throws IllegalAccessException, InstantiationException { B.class.newInstance(); } } When I use reflection to create an object from B, it give me the following exception: java.lang.IllegalAccessException: Class DefaultConstructor can not access a member of class DefaultConstructor$B with modifiers “private” Let us see which member the DefaultConstructor is trying to access by viewing the source. Source Code The following is part of source code of Class#newInstance() Constructor<T> tmpConstructor = cachedConstructor; // Security check (same as in java.lang.reflect.Constructor) int modifiers = tmpConstructor.getModifiers(); if (!Reflection.quickCheckMemberAccess( this , modifiers)) { Class<?> caller = Reflection.getCallerClass(); if (newInstanceCallerCache != caller) { Reflection.ensureMemberAccess(caller,...

Auto Update Java Source Code on Linux

Origin When debugging some Java applications or learning the internal implementations of some library class, we need to read the source code. So I download source from some sites. Soon, it caused some inconvenience. The class file will update whenever the package updates, now it change to: openjdk version “1.8.0_102” But my source code is still the old version. In the intellij idea, it will remind me that class file and source code is mismatched and has some diff. It may be no harm at first glance, but when we need to find the line where class file throws an exception, we may find an mismatched line. Like above picture shows, we can’t following the line number to find the right line if source code and class file is mismatched. And for the same reason, you can’t set a break point in library class file. Solution In order to sync the source code with class file automatically, we have to install a source package, making them updating at the same time. The following ...

Generic Implementation and Limitation

In the Generic Common Usage , we introduced some common usage about java generic: extends , ? super T , wildcard usage. Now, we come to how generic is implemented and what this implementation brings to us. The implementation of generic – erase We all hear that Java generic is implemented by erase, but what does that mean? More specific, how erase affect the byte code, and Java run time environment. Byte code In order to achieve the back-compatibility, Java use erase to implement generic. This is what we commonly heard, and how erase makes it? It’s simple. Making all byte code same, whether it uses generic or not. In this way, you can invoke old library without generic and they can invoke new generic code without worry. Just because the byte code makes no difference. we can see from following snippet that the byte code use generic is almost the same with code not using generic. // pre Java5 generic code public static void swapAgain (Object[] ts, int i, int j)...