zoukankan      html  css  js  c++  java
  • Effective Java 54 Use native methods judiciously

    Java Native Interface(JNI) allows Java applications to call native methods, which are special methods written in native programming languages such as C or C++.

    Historical usages of native methods

    1. Access to platform-specific facilities such as registries and file locks.
    2. Access to libraries of legacy code.
    3. Access to native methods written for performance-critical part of application.

    Disadvantage of native methods

    1. Native language are not safe (Item 39), native methods are no longer immune to memory corruption errors.
    2. Since native languages are platform dependent, application use them are far less possible.
    3. Difficult to debug.
    4. Fixed cost associated with going into and out of native code.
    5. It requires "glue code" that is difficult to read and tedious to write.

    Summary

    Think twice before using native methods. Rarely, if ever, use them for improved performance. If you must use native methods to access low-level resources or legacy libraries, use as little native code as possible and test it thoroughly. A single bug in the native code can corrupt your entire application.  

  • 相关阅读:
    年入50万的众生相
    【史上最全面经】银行类
    Dubbo背景和简介
    剑指Offer66题的总结、目录
    如何写一份更好的简历
    Linux命令 file
    Linux命令 umask
    Linux perm
    Linux 命令 which whereis locate find
    Linux命令 diff cmp patch
  • 原文地址:https://www.cnblogs.com/haokaibo/p/use-native-methods-judiciously.html
Copyright © 2011-2022 走看看