[A] is the time to upgrade java11 jdk11 advantage and select jdk

Box Contents

  1. It's time to upgrade java11 the -01-jdk11 advantage and select jdk
  2. -02- java11 was time to upgrade the upgrade jdk11 stepped pit remember
  3. It is time to upgrade the java11 -03 virtual machine Jvm parameter settings
  4. It's time to upgrade java11 the http2 http2 communication within -04 micro-services Clear Text (h2c)
  5. It's time to upgrade java11 the obstacles and problems h2c communications within -05 micro-service solutions

Java8 commercial fees

From January 2019 began, Oracle JDK began after 8 Java SE version to begin commercial fee, to be exact release after 8u201 / 202. If you use a function in Java if it is for commercial purposes, if do not want to spend money to buy it, the latest version is available free 8u201 / 202. Of course, if an individual client or individual developers can try free versions of all Oracle JDK.

Java11 performance boost

Java 11 only by switching to 16% have improved, this improvement may be due Java 10 introduced JEP 307: Parallel Full GC for G1.

For details, see Java 11 how much faster than 8? Look at this benchmark

List java 11 to change from the java 8

Description : That which we will not go all the features, listed only as part of change developers are most concerned about.

Compact strings

Starting from the data carried by the Java 9 String char [] to byte [] a compact string, in many cases in the Latin-1 contains only the characters, which can save half of the memory.

Enhanced api

1. String reinforcing @since 11

// 判断字符串是否为空白
" ".isBlank(); // true
// 去除首尾空格
" Hello Java11 ".strip(); // "Hello Java11"
// 去除尾部空格 
" Hello Java11 ".stripTrailing(); // " Hello Java11"
// 去除首部空格 
" Hello Java11 ".stripLeading(); // "Hello Java11 "
// 复制字符串
"Java11".repeat(3); // "Java11Java11Java11"
// 行数统计
"A\nB\nC".lines().count(); // 3复制代码

2. Enhanced collection

Java 9 from the beginning, jdk inside it as a collection (List, Set, Map) and an increase of copyOf method. They are used to create immutable collections.

  • of() @since 9
  • copyOf() @since 10

Example 1:

var list = List.of("Java", "Python", "C"); //不可变集合
var copy = List.copyOf(list); //copyOf判断是否是不可变集合类型,如果是直接返回
System.out.println(list == copy); // true
var list = new ArrayList<String>(); // 这里返回正常的集合
var copy = List.copyOf(list); // 这里返回一个不可变集合
System.out.println(list == copy); // false复制代码

Example Two:

var set = Set.of("Java", "Python", "C");
var copy = Set.copyOf(set);
System.out.println(set == copy); // true
var set1 = new HashSet<String>();
var copy1 = List.copyOf(set1);
System.out.println(set1 == copy1); // false复制代码

Example Three:

var map = Map.of("Java", 1, "Python", 2, "C", 3);
var copy = Map.copyOf(map);
System.out.println(map == copy); // true
var map1 = new HashMap<String, Integer>();
var copy1 = Map.copyOf(map1);
System.out.println(map1 == copy1); // false复制代码

Note: Use of collections and copyOf created immutable collection can not add, delete, replace, sorting and other operations, or will be reported java.lang.UnsupportedOperationException exceptions, Set.of () can not duplicate elements, Map.of () can not duplicate key, otherwise return java.lang.IllegalArgumentException. .

3.Stream enhance @since 9

Stream is a property of 8 Java, the Java 9 in its new four methods:

3.1 ofNullable(T t)

This method can receive a null to create an empty stream

// 以前
Stream.of(null); //报错
// 现在
Stream.ofNullable(null);复制代码

3.2 takeWhile(Predicate predicate)

This method determines the interface Predicate to true if taken out to generate a new stream, as long as the false terminated encountered, regardless of whether the element meets the conditions behind.

Stream<Integer> integerStream = Stream.of(6, 10, 11, 15, 20);
Stream<Integer> takeWhile = integerStream.takeWhile(t -> t % 2 == 0);
takeWhile.forEach(System.out::println); // 6,10复制代码

3.3 dropWhile(Predicate predicate)

This method determines the interface Predicate If true discarded to generate a new stream, as long as the false terminated encountered, regardless of whether the element meets the conditions behind.

Stream<Integer> integerStream = Stream.of(6, 10, 11, 15, 20);
Stream<Integer> takeWhile = integerStream.dropWhile(t -> t % 2 == 0);
takeWhile.forEach(System.out::println); //11,15,20复制代码

3.4 iterate overloaded

Iterate previously generated using the method with an infinite stream needs to be cut off limit

Stream<Integer> limit = Stream.iterate(1, i -> i + 1).limit(5);
limit.forEach(System.out::println); //1,2,3,4,5复制代码

After this reload now determine the parameters of a method of increasing the

Stream<Integer> iterate = Stream.iterate(1, i -> i <= 5, i -> i + 1);
iterate.forEach(System.out::println); //1,2,3,4,5复制代码

4.Optional enhance @since 9

4.1 stream()

If the stream is empty return an empty, if not empty value Optional turn into one stream.

//返回Optional值的流
Stream<String> stream = Optional.of("Java 11").stream();
stream.forEach(System.out::println); // Java 11

//返回空流
Stream<Object> stream = Optional.ofNullable(null).stream();
stream.forEach(System.out::println); // 复制代码

4.2 ifPresentOrElse(Consumer action, Runnable emptyAction)

This method is a combination of personal feeling isPresent () enhanced Else, use ifPresentOrElse approach is that if a Optional contains the value, the value of its action contained in the calling function, namely action.accept (value), which is consistent with ifPresent; and ifPresent difference method is that, ifPresentOrElse there is a second argument emptyAction - Optional If that does not contain a value, then ifPresentOrElse will call emptyAction, namely emptyAction.run ().

Optional<Integer> optional = Optional.of(1);
optional.ifPresentOrElse( x -> System.out.println("Value: " + x),() ->
System.out.println("Not Present.")); //Value: 1

optional = Optional.empty();
optional.ifPresentOrElse( x -> System.out.println("Value: " + x),() ->
System.out.println("Not Present.")); //Not Present.复制代码

4.3 or(Supplier > supplier)

Optional<String> optional1 = Optional.of("Java");
Supplier<Optional<String>> supplierString = () -> Optional.of("Not Present");
optional1 = optional1.or( supplierString);
optional1.ifPresent( x -> System.out.println("Value: " + x)); //Value: Java
optional1 = Optional.empty();
optional1 = optional1.or( supplierString);
optional1.ifPresent( x -> System.out.println("Value: " + x)); //Value: Not Present复制代码

5.InputStream enhance @since 9

String lxs = "java";
try (var inputStream = new ByteArrayInputStream(lxs.getBytes());
    var outputStream = new ByteArrayOutputStream()) {
    inputStream.transferTo(outputStream);
    System.out.println(outputStream); //java
}复制代码

HTTP Client API

Api supports synchronous and asynchronous changed in two ways, the following are examples of two ways:

var request = HttpRequest.newBuilder()
    .uri(URI.create("https://www.baidu.com/"))
    .build();
var client = HttpClient.newHttpClient();
// 同步
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
// 异步
CompletableFuture<HttpResponse<String>> sendAsync = client.sendAsync(request, HttpResponse.BodyHandlers.ofString());
//这里会阻塞
HttpResponse<String> response1 = sendAsync.get();
System.out.println(response1.body());复制代码

Remove content

  • com.sun.awt.AWTUtilities。
  • sun.misc.Unsafe.defineClass 使用java.lang.invoke.MethodHandles.Lookup.defineClass来替代。
  • Thread.destroy () and Thread.stop (Throwable) method.
  • sun.nio.ch.disableSystemWideOverlappingFileLockCheck 属性。
  • sun.locale.formatasdefault property.
  • jdk snmp module.
  • javafx, openjdk from java10 version is removed, oracle java10 has not yet been removed javafx, and java11 javafx version will be removed.
  • Java Mission Control, then remove from the JDK, so you need to download separately.
  • Root Certificates :Baltimore Cybertrust Code Signing CA,SECOM ,AOL and Swisscom。
  • Tag in the waste java9 java11 in CORBA and Java EE module removed off.

Full support for Linux containers (including docker)

Many applications run in a Java virtual machine (including Apache Spark and Kafka and other data services as well as traditional enterprise applications) can run Docker containers. But running a Java application Docker containers there has been a problem that runs in a container JVM program after setting the memory size and CPU usage, can lead to decreased performance of the application. This is because the Java application does not realize that it is running in the container. With the release of Java 10, this problem is finally solved, JVM now recognizes the constraints set by the container control groups (cgroups). Memory and CPU constraints may be used in a container directly managing Java applications, including:

  • Comply memory limit set in container
  • The available CPU in the container
  • CPU constraint is provided in the container

JDK Recommended

Because Java 11 start, Oracle is providing paid support business version. I recommend this more use Amazon Corretto, Corretto under a GPL license.

Corretto long-term support (LTS), including 8 Corretto performance enhancements and security updates, provide free until at least June 2023. Released an update plans every quarter.

Amazon will Corretto 11 LTS provides quarterly updates, at least until August 2024.

Github Download: https: //github.com/corretto/corretto-8/releaseshttps: //github.com/corretto/corretto-11/releases

statement

This series of articles by the micro-services mica core components of a dream technology jointly organize writing and, if the reference or reproduced, please indicate the source and retain the original author.image

Guess you like

Origin juejin.im/post/5e4df461e51d4526cd1de49a