这篇文章主要介绍“Java8精简的JRE举例分析”,在日常操作中,相信很多人在Java8精简的JRE举例分析问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Java8精简的JRE举例分析”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
1.更小的Java环境需要更少的计算资源。
2.一个较小的运行时环境可以更好的优化性能和启动时间。
3.消除未使用的代码从安全的角度总是好的。
4.这些打包的应用程序可以下载速度更快。
紧凑的JRE分3种,分别是compact1、compact2、compact3,他们的关系是compact1<compact2<compact3,他们包含的API如下图所示
javac –bootclasspath, or javac –profile <profile>
如果不符合compact的api,则报错。
?
1 2 3 4 5 6 7 8 | $ javac -profile compact2 Test.java Test.java:7: error: ThreadMXBean is not available in profile 'compact2' ThreadMXBean bean = ManagementFactory.getThreadMXBean(); ^ Test.java:7: error: ManagementFactory is not available in profile 'compact2' ThreadMXBean bean = ManagementFactory.getThreadMXBean(); ^ 2 errors |
java8新增一个工具,用来分析应用程序所依赖的profile,有三个参数比较常用 -p,-v,-r
?
1 2 3 4 5 6 7 8 9 | import java.util.Set; import java.util.HashSet;
public class Deps { public static void main(String[] args) { System.out.println(Math.random()); Set<String> set = new HashSet<>(); } } |
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ************** PROFILE ******************** jdeps -P Deps.class Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar <unnamed> (Deps.class) -> java.io compact1 -> java.lang compact1 -> java.util compact1
************** VERBOSE ******************** jdeps -v Deps.class Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar Deps (Deps.class) -> java.io.PrintStream -> java.lang.Math -> java.lang.Object -> java.lang.String -> java.lang.System -> java.util.HashSet
************** RECURSIVE ******************** jdeps -R Deps.class Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar <unnamed> (Deps.class) -> java.io -> java.lang -> java.util /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jce.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar javax.crypto (jce.jar) -> java.io -> java.lang -> java.lang.reflect -> java.net -> java.nio -> java.security -> java.security.cert -> java.security.spec -> java.util -> java.util.concurrent -> java.util.jar -> java.util.regex -> java.util.zip -> javax.security.auth -> sun.security.jca JDK internal API (rt.jar) -> sun.security.util JDK internal API (rt.jar) -> sun.security.validator JDK internal API (rt.jar) javax.crypto.interfaces (jce.jar) -> java.lang -> java.math -> java.security javax.crypto.spec (jce.jar) -> java.lang -> java.math -> java.security.spec -> java.util /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jce.jar java.security (rt.jar) -> javax.crypto JDK internal API (jce.jar) sun.security.util (rt.jar) -> javax.crypto JDK internal API (jce.jar) -> javax.crypto.interfaces JDK internal API (jce.jar) -> javax.crypto.spec JDK internal API (jce.jar) |
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | $ hg clone http://hg.openjdk.java.net/jdk8/jdk8/ $ cd jdk8 $ make images profiles : ## Finished profiles (build time 00:00:27) ----- Build times ------- Start 2013-03-17 14:47:35 End 2013-03-17 14:58:26 00:00:25 corba 00:00:15 demos 00:01:50 hotspot 00:00:24 images 00:00:21 jaxp 00:00:31 jaxws 00:05:37 jdk 00:00:43 langtools 00:00:18 nashorn 00:00:27 profiles 00:10:51 TOTAL ------------------------- Finished building Java(TM) for target 'images profiles' $ cd images $ ls -d *image j2re-compact1-image j2re-compact2-image j2re-compact3-image j2re-image j2sdk-image |
到此,关于“Java8精简的JRE举例分析”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。