使用javac根据profile编译应用程序
javac –bootclasspath, or javac –profile
如果不符合compact的api,则报错。
- $ 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
使用工具开发的效果
JPEDS工具使用
java8新增一个工具,用来分析应用程序所依赖的profile,有三个参数比较常用 -p,-v,-r
- import java.util.Set;
- import java.util.HashSet;
-
- public class Deps {
- public static void main(String[] args) {
- System.out.println(Math.random());
- Set set = new HashSet<>();
- }
- }
- ************** PROFILE ********************
- jdeps -P Deps.class
- Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
- (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
- (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)
在linux上构建profile
- $ 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
编译后compact大致的占用空间
总结
如今,物联网正风行一时。我们看到大量不同的设备在市场上出现,每一种的更新速度都越来越快。java需要一个占用资源少的JRE运行环境,紧凑的JRE特性的出现,希望能带来以后的物联网的发展,甚至还是会有大量的java应用程序出现在物联网上面。目前oracle也发布了针对raspberry pi的JRE了。
另外该特性也是为java9的模块化项目做准备,模块化特性是javaer所期待的特性。他是解决业务系统复杂度的一个利器,当然OSGI也是相当的出色。但osgi对于新学者来说未免太复杂了。
原文链接:http://my.oschina.net/benhaile/blog/211804
当前文章:Java8新特性探究(8):精简的JRE详解
浏览地址:http://www.shufengxianlan.com/qtweb/news48/68848.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
广告
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源:
创新互联