Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fabrizio Marini.

Similar presentations


Presentation on theme: "Fabrizio Marini."— Presentation transcript:

1 Fabrizio Marini

2 WI-FI SSID: clear-guest User ID: guest Password:

3 Fabrizio Marini – www.fabriziomarini.com
1996 – Java in 21 Days +22 anni su Java 44% della mia vita January April 1996 Sottotenente di Vascello April 1996 – February 2003 Socio Fondatore February December 2008 Systems Engineer Principal December 2008 – Today Innovation Solution Architect

4 Oracle Innovation Lab Force - Italia
Gruppo Facebook

5 Oltre le slide vedremo .... Jshell, JMC Moduli --patch-module Jlink
Esempi live di alcune novità: Jshell, JMC Moduli --patch-module Jlink CDS & AppCDS Moduli in Docker Java10 - Docker awareness Docker & java: compilare dentro e fuori i container Graal

6 Oracle VM VirtualBox (Admin/password=fabrizio/fabrizio)
Menù «Impostazioni» Sistema->Memoria: 4096 Mb Sistema->Processore: 2 CPU Cartelle Condivise: Nome: fabrywork Percorso: D:\Fabry-Work Montaggio Automatico: Si Accesso: Completo Per accedere D:\Fabry-Work da Ubuntu: Sudo su cd /media/sf_fabrywork

7 OpenJDK - http://openjdk.java.net/
What is OpenJDK? OpenJDK (Open Java Development Kit) is a free and open source implementation of the Java Platform, Standard Edition (Java SE). OpenJDK is the official reference implementation of Java SE since version 7

8 Java LTS (Long Time Support)
>=Java11 (Java18.9) Link Oracle – Link OpenJDK – Video esplicativo – LTS updates will only be available for customers with a commercial support contract from Oracle. Public updates for JDK 11, like those of all other releases from JDK 9 onwards will stop after six months when the next version is released. - LTS: 3 Years - Premier Support: 5 years - Sustaining support: >5 OpenJDK: --- Adoptopenjdk.net LTS

9 Java 8 - Novità Espressioni Lambda operatore :: Metodi default:
Un’espressione lambda definisce una funzione anonima (ossia una funzione che ha un corpo ma non un nome) che mantiene lo stato. In pratica un metodo senza una dichiarazione e quindi senza nome, modificatori d’accesso, dichiarazione del tipo del valore di ritorno. operatore :: Serve per convertire un metodo normale in una espressione lambda Metodi default: le classi che implementano l’interfaccia ma non effettuano l’override del metodo in caso di invocazione di tale metodo offriranno l’implementazione di default Streams operazioni parallele (consentendo di sfruttare al meglio le moderne architetture multicore). Per quanto riguarda i pattern supportati, gli streams sono pensati per eseguire operazioni di filtraggio, mapping e riduzioni.  L’API Stream è integrata con le API Collections API per date e tempo, Classe Optional Profili Compatti. Nashorn(Javascript/java a/r) – jjs REPL - jjs> print('Hello World'); JVM – no MaxPermSize - gli sviluppatori non dovranno più preoccuparsi di stabilire dimensioni adeguate per la permanent generation.

10 Java 8 - Novità esempio

11 Java 9: Alcune Novità (... Oltre a varie ottimizzazioni di linguaggio)
Moduli Supporto Reactive Programming: Reactive Streams API asynchronous stream processing with non- blocking back pressure Supporto a HTTP/2 (package java.net.http) Supporto al protocollo DTLS (Datagram Transport Layer Security) G1 gc di default Jshell (REPL) Added JDK HTTP Client (sync & async) - handles request and response bodies as reactive-streams jshell -v --add-modules jdk.incubator.httpclient import jdk.incubator.http.*; Enhancements Process API

12 Jshell - Read-Evaluate-Print Loop (REPL)
>=Java9 [provate tryjshell.org] Esempi: jshell> new byte[140_000_000] System.gc() Jshell> MiaClasse.main(new String[0])

13 HTTP Client (java 9 & 10) Try it with jshell jshell -v --add-modules jdk.incubator.httpclient jshell> import jdk.incubator.http.*; jshell> HttpClient httpClient = HttpClient.newHttpClient(); jshell> HttpRequest httpRequest = HttpRequest.newBuilder().uri(new URI(" jshell> HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandler.asString()); jshell> System.out.println(httpResponse.statusCode()); jshell> System.out.println(httpResponse.body());

14 Java 10: Alcune Novità (... Oltre a varie ottimizzazioni di linguaggio)
Var: Local-Variable Type Inference Docker awareness AppCDS Graal:  compilatore just-in-time in fase sperimentale utilizzabile su piattaforme Linux con architettura x64 G1 : Parallel full garbage collection. The number of threads can be optionally configured using - XX:ParallelGCThreads Interessante anche l'abilitazione di HotSpot per l'allocazione dell'object heap (la zona di memoria che contiene gli oggetti) in una memoria alternativa specificata dall'utente, come per esempio un modulo NVDIMM; un'opzione utile quando ci si trova a dover lavorare con architetture di memoria differenti tra loro. Http Client: The implementation has been rewritten to be fully asynchronous. (WebSockets)

15 JMC – Java Mission Control – Novità: http://hg.openjdk.java.net/jmc
Aprendo un file JFR (Java Flight Recorder) anche di versioni precedenti , appare una finestra con consigli di ottimizzazioni relativamente ad eventuali problemi sul sistema e sull’applicazione.

16 Graal(VM) - Linux (CE/EE) or Mac OS X (EE) on x86 64-bit systems
>=java XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler JIT in C++: Errori memoria, difficile da mantenere Java: safety - exceptions rather than crashes, no real memory leaks or dangling pointers - good tooling, like being able to use debuggers, profilers, and tools like VisualVM - good IDE support, and more JIT in java?: “you give it a byte[] in and you want a byte[] back”. Java 9 introduce an experimental AOT (Ahead of Time) compiler and Graal is the basis of it. GraalVM Native Image Generation – «native-image tool» Truffle: framework for implementing languages using a simple abstract syntax tree interpreter Twitter utilizza GraalVM

17 Java 11 (18. 9): Alcune Novità (
Java 11 (18.9): Alcune Novità (... Oltre a varie ottimizzazioni di linguaggio) Http Client Local-Variable Syntax for Lambda Parameters (var x, var y) -> x.process(y) We’ll be able to simply write: (x, y) -> x.process(y) Epsilon An Arbitrarily Low-Overhead Garbage Collector: handles memory allocation, without implementing any actual memory reclamation mechanism Remove the Java EE and CORBA Modules Following the depreciation of the Java EE and CORBA modules in Java SE 9 Dynamic Class-File Constants LTS (Long Term Support)

18 Java Platform Module System (JPMS)
>=Java9 - java --list-modules - (Project Jigsaw) Mark Reinhold, Oracle’s Java platform chief architect, described the goals of the module system: Reliable configuration – to replace the brittle, error-prone class-path mechanism with a means for program components to declare explicit dependences upon one another. Strong encapsulation – to allow a component to declare which of its public types are accessible to other components, and which are not. It organizes packages and types in a way that is much easier to manage and maintain

19 I Moduli >=Java9 - module-info.java requires – indicates the module it depends on, also called dependency transitive – only used with the requires directive, indicating that the specified dependency is also accessible to those requiring this module exports – declares a package accessible to other modules opens – exposes a package at runtime for introspection with the Reflection API uses – specifies the fully qualified name of a service this module consumes provides … with – denotes an implementation, specified by the with keyword, for a service, indicated by provides

20 I Moduli >=Java9 Unnamed Module: On the classpath you can include all your older Java classes, the classes in the unnamed module are only readable by other classes in the unnamed module. No named module can read the classes of the unnamed module. All classes in the unnamed module requires all modules found on the module path. That way, all classes in the unnamed module can read all classes exported by all the Java modules found on the module path. The unnamed module exports all its packages. All classes in the unnamed module requires all modules found on the module path. Your own named modules cannot use an Unnamed Module.

21 I Moduli >=Java9 Automatic Module : An automatic module is made from a JAR file with Java classes that are not modularized, meaning the JAR file has no module descriptor. When you place an ordinary JAR file on the module path (not the classpath) the Java VM will convert it to an automatic module at runtime. An automatic module requires all named modules on the module path. In other words, it can read all packages exported by all named modules in the module path. If your application contains multiple automatic modules, each automatic module can read the classes of all other automatic modules. An automatic module can read classes in the unnamed module. This is different from explicit named modules (real Java modules) which cannot read classes in the unnamed module. An automatic module exports all its packages, so all named modules on the module path can use the classes of an automatic module. Named modules still have to explicitly require the automatic module though.

22 I Moduli: Alcuni «Command Line Options»
>=Java9 (for java & javac) --add-exports, --add-opens, --add-modules, --patch-module … --add-exports the package is exported, meaning all public types and members therein are accessible at compile and run time. --add-opens the package is opened, meaning all types and members (not only public ones!) therein are accessible at run time (Deep Reflection) java --add-modules java.xml.ws.annotation --patch-module java.xml.ws.annotation=jsr jar --class-path $dependencies -jar $appjar Esempio

23 I Moduli: Multi Java Version Module JAR Files
>=Java9 - MANIFEST.MF: Multi-Release: true The com folder at the root level of the JAR file contains the compiled Java classes for pre Java 9 versions. Earlier versions of Java do not understand multi Java version JAR files so they use the classes found here. Therefore you can only support one Java version earlier than Java 9

24 CDS & AppCDS «This is just the beginning to improve Java startup and efficiency» CDS&AppCDS allows you to reduce launch times, response time outliers, and, if you run several JVMs on the same machine, memory footprint. CDS (>=jdk5) AppCDS (>=jdk10) In this release, CDS cannot archive classes from user-defined modules (such as those specified in -- module-path). We plan to add that support in a future release.

25 CDS cds_off.log: cds_on.log:
/home/fabrizio/workshop/JDK10HTTP/out-standalone/bin - cds_on.log - cds_off.log cds_off.log: [0.011s][info][class,load] opened: /home/fabrizio/workshop/JDK10HTTP/out-standalone/lib/modules [0.027s][info][class,load] java.lang.Object source: jrt:/java.base [0.027s][info][class,load] java.io.Serializable source: jrt:/java.base [0,350s][info][class,load] com.fabry.miomodulo.MyHandler source: jrt:/com.fabry.miomodulo [0,367s][info][class,load] java.nio.channels.spi.AbstractSelector$1 source: jrt:/java.base cds_on.log: [0.002s][info][class,load] opened: /home/fabrizio/workshop/JDK10HTTP/out-standalone/lib/modules [0.012s][info][class,load] java.lang.Object source: shared objects file [0.012s][info][class,load] java.io.Serializable source: shared objects file [0,223s][info][class,load] com.fabry.miomodulo.MyHandler source: jrt:/com.fabry.miomodulo [0,238s][info][class,load] java.nio.channels.spi.AbstractSelector$1 source: jrt:/java.base

26 CDS & AppCDS cds_on.log: app_cds_on.log:
/home/fabrizio/workshop/JDK10HTTP/out-standalone/bin - cds_on.log – app_cds_on.log cds_on.log: [0,223s][info][class,load] com.fabry.miomodulo.MyHandler source: jrt:/com.fabry.miomodulo [0,238s][info][class,load] java.nio.channels.spi.AbstractSelector$1 source: jrt:/java.base app_cds_on.log: [0,209s][info][class,load] com.fabry.miomodulo.MyHandler source: shared objects file [0,229s][info][class,load] java.nio.channels.spi.AbstractSelector$1 source: shared objects file

27 Varie G1: -XX:MaxGCPauseMillis=<nnn>
Cose utili ... G1: -XX:MaxGCPauseMillis=<nnn> Throughput Goal specified by “-XX:GCTimeRatio=nnn” The throughput goal is measured in terms of the time spent collecting garbage, and the time spent outside of garbage collection is the application time. The ratio of garbage collection time to application time is 1/ (1+nnn). For example, - XX:GCTimeRatio=19 sets a goal of 1/20th or 5% of the total time for garbage collection java -XX:+PrintFlagsFinal -version | grep MaxHeapSize java -XX:+PrintFlagsFinal -version | grep -i GCThreads se si limitano le CPU i dati si abbassano, per reimpostarli «-XX:ParallelGCThreads»

28


Download ppt "Fabrizio Marini."

Similar presentations


Ads by Google