本文是我的在企業內部分享使用的簡要大綱,列舉了JAVA9-12的重要更新,文章的結構較簡單,也不規範,鑑於近期寫若干文章時總會忘記一些新特性所處的版本,特將此大綱流copy留用。java
一 JAVA9 新特性shell
1.Java Platform Module System/ Modular Java Application Packaging模塊化系統及類加載器分級編程
2.jshellapi
3.Multi-Release JAR Files 多版本的jar包數組
4.Jlink 工具緩存
5.Segmented Code Cache 代碼片斷緩存併發
6.Dynamic Linking of Language-Defined Object Models 動態連接語言定義模型框架
7.Unified JVM Logging 統一JVM日誌jvm
8.將G1做爲默認垃圾收集器,並deprecated CMS.ide
9.進程API
10.變量句柄
11.字符串內部實現優化(字符數組變字節數組+編碼方式)
12.發佈訂閱框架
13.集合工廠方法
14.自旋暗示
15.對象序列化數據過濾
16."棧旅行者"
17.Milling Project Coin(鬼知道該怎麼翻譯).
Allow @SafeVargs on private instance methods. //容許在私有實例方法上標註@SafeVargs註解
Allow effectively final variables to be used as resources in the try-with-resourcesstatement. //try-with-resource 語法支持實際final的變量
Allow the diamond with anonymous classes if the argument type of the inferred type is denotable.//容許對可推薦出類型的匿名內部類使用鑽石符號.
Complete the removal, begun in Java SE 8, of the underscore from the set of legal identifier names.//移除java8中已經開始的,如下劃線做爲完整標識符名稱
Add support for private interface methods.//接口中可定義私有方法.
18.擴大的unicode集
19.孵化官方http client.
二 JAVA10
1.局部變量類型推斷
2.統必定義的 GC接口.
3.g1垃圾收集器的並行full gc
4.應用類數據共享
5.thread local 握手
6.擴展unicode語言標籤.
三. JAVA11
1.unicode10支持
2.標準化java9中孵化的http客戶端
demo:同步式編程
public void get(String uri) throws Exception {
HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(uri)) .build(); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); }
demo:響應式編程
public CompletableFuture<String> getCompletableFuture(String uri) {
HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(uri)) .build(); return client.sendAsync(request, HttpResponse.BodyHandlers.ofString()) .thenApply(HttpResponse::body); }
demo:響應式編程-併發
public void testConcurrentRequests(){
HttpClient client = HttpClient.newHttpClient(); List<String> urls = List.of("http://www.baidu.com","http://www.alibaba.com/","http://www.tencent.com"); List<HttpRequest> requests = urls.stream() .map(url -> HttpRequest.newBuilder(URI.create(url))) .map(reqBuilder -> reqBuilder.build()) .collect(Collectors.toList()); List<CompletableFuture<HttpResponse<String>>> futures = requests.stream() .map(request -> client.sendAsync(request, HttpResponse.BodyHandlers.ofString())) .collect(Collectors.toList()); futures.stream() .forEach(e -> e.whenComplete((resp,err) -> { if(err != null){ err.printStackTrace(); }else{ System.out.println(resp.body()); System.out.println(resp.statusCode()); } })); CompletableFuture.allOf(futures .toArray(CompletableFuture<?>[]::new)) .join(); }
注:以上代碼是分享時從網上轉來的,由於此文是從內部wiki粘過來,出處已忘。接下來打算髮一篇CompletableFuture有關的文章,最近對響應式編程的興趣更加深入了。
3.Collection.toArray(IntFunction) Default 方法
4.編譯器線程的懶分配
5.體驗版zgc大殺器(缺乏類和元數據卸載)
6.Epsilon GC no-op 體驗版
7.少代價的堆分析工具jvmti
8.nests, an access-control context ,省去編譯器插入accessibility-broadening bridge methods
9.一些屬性變事實的只讀.java.home, user.home, user.dir, user.name等
10.Reference類再也不支持克隆
11.使用classpath進行編譯運行時,默認解析的模塊策略變動:root模塊集在此版本變動爲全部可見的導出api的系統模塊,惟一可見的改變是java.se模塊不在默認解析.
12.SelectableChannel能夠在select操做正在進行中註冊.
13.DatagramChannel.send Throws AlreadyConnectedException Instead of IllegalArgumentException
14.爲併發gc提供新的性能記數器
15.g1支持自適應的引用處理時的線程數.全部gc支持stw階段的並行自適應.
16.模塊路徑下支持類數據共享cds.
四.JAVA12
1.unicode11支持
2.jvm常量api
3.簡寫的數字格式:1k
4.zgc支持併發類數據卸載
5.支持交替在內存設備上分配老年代,支持相應功能的設備如"非易變-雙列直插式內存模型"(NV-DIMM).
6.switch case支持語句的同時支持表達式.case ... ->
7.更好的支持http重定向(HttpURLConnection)
8.g1可能在併發標記週期交回內存.
9可終止的g1混合gc
10.讓g1在空閒時自動交回已提交但未使用的內存.
11.Shenandoah 低停頓gc體驗版.