{"id":444,"date":"2019-02-25T11:49:58","date_gmt":"2019-02-25T02:49:58","guid":{"rendered":"http:\/\/localhost:8000\/?p=444"},"modified":"2021-01-23T11:51:28","modified_gmt":"2021-01-23T02:51:28","slug":"java-tips","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/02\/java-tips.html","title":{"rendered":"Java\u306eTips"},"content":{"rendered":"

Java\u306b\u95a2\u9023\u3059\u308bTips\u3002\u4eca\u5f8c\u306fJava\u3067\u5b9f\u88c5\u3059\u308b\u6a5f\u4f1a\u3082\u5c11\u306a\u304f\u306a\u308b\u3068\u306f\u601d\u3046\u3051\u3069\u3001\u304a\u308a\u306b\u3075\u308c\u3066\u8ffd\u8a18\u3057\u3066\u3044\u304f\u4e88\u5b9a\u3002<\/p>\n

\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n

\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n
# \u6700\u65b0\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nbrew cask install java # 2019\u5e744\u6708\u73fe\u5728\u3060\u3068jdk12\u304cinstall\u3055\u308c\u308b\n\n# \u904e\u53bb\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nbrew tap homebrew\/cask-versions\n# brew cask install java8 #\u914d\u5e03\u505c\u6b62\u305a\u307f\nbrew cask install adoptopenjdk8\nbrew cask install java11<\/code><\/pre>\n

JAVA_HOME\u78ba\u8a8d<\/h3>\n
\/usr\/libexec\/java_home -v 1.8\n> \/Library\/Java\/JavaVirtualMachines\/adoptopenjdk-8.jdk\/Contents\/Home\n\/usr\/libexec\/java_home -v 11\n-> \/Library\/Java\/JavaVirtualMachines\/openjdk-11.0.2.jdk\/Contents\/Home\n\/usr\/libexec\/java_home -v 12\n-> \/Library\/Java\/JavaVirtualMachines\/openjdk-12.0.1.jdk\/Contents\/Home<\/code><\/pre>\n

JAVA_HOME\u5207\u308a\u66ff\u3048<\/h3>\n

alias\u3092\u8a2d\u5b9a\u3057\u3066\u304a\u304d\u3001java12<\/code>, java8<\/code>\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u5207\u308a\u66ff\u3048\u308b<\/p>\n

alias java8='export JAVA_HOME=`\/usr\/libexec\/java_home -v 1.8`'\nalias java11='export JAVA_HOME=`\/usr\/libexec\/java_home -v 11`'\nalias java12='export JAVA_HOME=`\/usr\/libexec\/java_home -v 12`'<\/code><\/pre>\n

\u30e1\u30e2\u30ea\u8abf\u67fb\u95a2\u4fc2<\/h2>\n

\u30ed\u30fc\u30ab\u30eb\u3067\u52d5\u3044\u3066\u3044\u308bjava\u306e\u76e3\u8996<\/h3>\n
    \n
  • GC\u306e\u5b9f\u884c<\/li>\n
  • \u30d2\u30fc\u30d7\u30c0\u30f3\u30d7\u53d6\u5f97\n
    jvisualvm -J-Xmx1024m<\/code><\/pre>\n<\/li>\n<\/ul>\n

    jConsole<\/h3>\n
      \n
    • \u30e1\u30e2\u30ea\u4f7f\u7528\u72b6\u6cc1\u3092\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u76e3\u8996<\/li>\n
    • \u5916\u304b\u3089GC\u3092\u304b\u3051\u3089\u308c\u308b<\/li>\n<\/ul>\n

      java \u30d7\u30ed\u30bb\u30b9ID\u3092\u8abf\u3079\u308b<\/h3>\n
      jps -l<\/code><\/pre>\n

      GC\u306e\u624b\u5b9f\u884c<\/h3>\n
      jcmd ${\u30d7\u30ed\u30bb\u30b9ID} GC.run<\/code><\/pre>\n

      thread dump\u306e\u53d6\u5f97<\/h3>\n
      jstack ${\u30d7\u30ed\u30bb\u30b9ID} > ${\u30d5\u30a1\u30a4\u30eb\u540d}   # hoge.tdump<\/code><\/pre>\n

      heap dump\u306e\u53d6\u5f97<\/h3>\n
      df -h \/${\u5bfe\u8c61\u30d5\u30a9\u30eb\u30c0}\njmap -dump:format=b,file=${\u30d5\u30a1\u30a4\u30eb\u540d} ${\u30d7\u30ed\u30bb\u30b9ID}   # hoge.hprof<\/code><\/pre>\n

      Eclipse Memory Analizer<\/h3>\n
        \n
      • Eclipse Plugin<\/li>\n
      • \u30ed\u30fc\u30ab\u30ebPC\u3067\u5b9f\u884c\u4e2d\u306eJVM\u3084GC\u30c0\u30f3\u30d7\u3092\u53d6\u308a\u8fbc\u3093\u3067\u5206\u6790\n
          \n
        • \u5b9f\u884c\u4e2d\u306eJVM\u3092\u5206\u6790\u3059\u308b\u5834\u5408\u3001\u53d6\u308a\u8fbc\u3093\u3060\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u3001\u3044\u3063\u305f\u3093dump\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b<\/li>\n
        • 1G\u30af\u30e9\u30b9\u306edump\u30d5\u30a1\u30a4\u30eb\u3092\u89e3\u6790\u3059\u308b\u306b\u306f\u3001\u305d\u308c\u3092\u8aad\u307f\u8fbc\u3080\u5fc5\u8981\u304c\u3042\u308a\u305d\u308c\u3060\u3051\u3067\u6570\u5206\u304b\u304b\u3063\u305f\u30fb\u30fb\u30fb<\/li>\n<\/ul>\n<\/li>\n
        • Leek suspects -> Dominator Tree\u3092\u898b\u3066\u3044\u304f\u3068\u3001\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3057\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5206\u304b\u308b<\/li>\n
        • \u300cShallow Heap\u300d\u306f\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u81ea\u4f53\u306e\u30b5\u30a4\u30ba\u3002\u300cRetained Heap\u300d\u306f\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff0b\u5b50\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5408\u8a08\u30b5\u30a4\u30ba\n