




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、云时代的Java 13技术新特性Java SE remains importantEase of UseLanguage fundamentals based on improving C+ to provide powerful, simple to use language.ReliabilityJava is strongly typed with heavily tested libraries and extensive tooling making Java robust.SecurityJavas architecture, originally designed for emb
2、edded devices, was designed with security in mind.Platform IndependenceWrite once, run anywhere. Operating system and hardware agnostic.#1Programming Language12MDevelopers run Java80%of enterprises run Java SE38BActive JVM globally#1Developer choice in the cloudOracle commitments for JavaMake Java m
3、ore openDeliver enhancements and innovation faster Continue support for the Java ecosystemJava continues to thriveTwo Decades of InnovationJava continues to evolve with important language features such as Generics in Java 5, Lambdas in Java 8 and Modules in Java 9 boosting performance, stability and
4、 security of the platform along the way./tiobe-indexReady for the CloudRelease cadence changes introduced in 2017 mean important features are delivered faster. Many of Javas humble embedded roots make it ideal for Cloud low memory foot print, fast startup and data isolation.Oracle Java SE binaries r
5、elease cadenceSupporting choice of migration paths - Every 6 months or every 3 years Predictable, incremental, approachableJava SE 18Java SE 17Java SE 16Java SE 15Java SE 14Java SE 13Java SE 12Java SE 11Java SE 10Java SE 9Java SE 8Java SE 720142015201620172018201920202021202220232024Public (Free) Up
6、datesOracle Commercial SupportGAOracle offers users choice/javadownloadBrought to you by OracleLeading author/contributor of Java technologyLeading sponsor/steward of the Java ecosystemDriving platform innovationJDK 13 September 20195 JEPs2 Preview FeaturesSwitch Expression remains in preview with c
7、hanges.Text BlocksJava SE 13Improving productivity, performance and scalability(JEP 354) Switch Expressions (Preview): Simplifies every day coding and prepares the way for future features such as pattern matching (JEP 305).(JEP 355) Text Blocks (Preview): Simplifies the task of expressing strings th
8、at span several lines of source code.Preview Language and VMDescribed in JEP 12A preview language or VM feature is a new feature of the Java SE Platform that is fully specified, fully implemented, and yet impermanent.Using a preview feature (compiler + launcher)javac -enable-preview Foo.java (-relea
9、se $N or -source $N could be used)java -enable-preview FooIDEs provide supportcase MONDAY: case FRIDAY: case SUNDAY: numLetters = 6;break;case TUESDAY: numLetters = 7; break;case THURSDAY: case SATURDAY: numLetters = 8;break;case WEDNESDAY:numLetters = 9; break;default:throw new UnexpectedDayExcepti
10、on(day);enum DayOfWeek MONDAY, TUESDAY, WEDNESDAY,THURSDAY, FRIDAY, SATURDAY, SUNDAYint numLetters = switch (day) case MONDAY, FRIDAY, SUNDAY - 6;case TUESDAY- 7;case THURSDAY, SATURDAY- 8;case WEDNESDAY- 9;/ No default needed;Java SE 13(JEP 354) Switch Expressions (Preview Feature)int numLetters; s
11、witch (day) / Traditional caseint numLetters = switch (day) case MONDAY:case FRIDAY: case SUNDAY:yield 6;case TUESDAY: yield 7;case THURSDAY: case SATURDAY:yield 8;case WEDNESDAY:yield 9;Java SE 13(JEP 354) Switch Expressions (Preview Feature)To yield a value from a switch expression, the break with
12、 value statement is dropped in favor of a yield statement./ New caseint numLetters = switch (day) case MONDAY, FRIDAY, SUNDAY - 6; case TUESDAY - 7;case THURSDAY, SATURDAY - 8;default - int len = day.toString().length(); yield len;n +Hello, worldn +n +n;String html = Hello, world ;Java SE 13(JEP 355
13、) Text Blocks (Preview Feature)String html = n +Multi-line strings requirequotes and concatenationon each lineError-prone for snippets of JSON, SQL, HTML etcManual manglingintroduces errors, harderto readA text block is a multi-linestring literal that avoidsthe need for most escapesequences, automat
14、icallyformats the string in apredictable way, andgives the developercontrol over format whendesired.Java SE 13(JEP 355) Text Blocks (Preview Feature)The (column) position of the closing delimiter is significant. Its part of the list of line to calculate the left margin. All spaces left of the leftmo
15、st line is incidental, thus removed.String html = Hello, world;Project AmberOther enhancements coming soon or in phases(JEP 359) Records: Records provide a compact syntax for declaring classes which are transparent holders for shallowly immutable data.(JEP 360) Sealed Types: Sealed types are classes
16、 or interfaces that impose restrictions on which other classes or interfaces may extend or implement them.(JEP 305) Pattern Matching for instanceof: Pattern matching allows common logic in a program - conditionally extracting components from objects - to be expressed more concisely and safely. JEP 3
17、54 Switch Expressions in JDK13 are ready for pattern matchingProject AmberJEP 305: Pattern Matching for instanceofWe write test-and extract code all the timeType name is repeated in both instanceof test and castif (obj instanceof Integer) int intValue = (Integer) obj).intValue();/ use intValueLets s
18、ee Pattern Matchingif (obj instanceof Integer intValue) / use intValueProject AmberJEP 305: Pattern Matching for instanceofExample - Consider the following equality methodOverridepublic boolean equals(Object o) return (o instanceof CaseInsensitiveString) & (CaseInsensitiveString) o).s.equalsIgnoreCa
19、se(s);Overridepublic boolean equals(Object o) return (o instanceof CaseInsensitiveString cis) & cis.s.equalsIgnoreCase(s); / Short, Boolean, etcProject AmberJEP 305: Pattern Matching for instanceofString formatted = unknown; if (constant instanceof Integer) int i = (Integer) constant;formatted = Str
20、ing.format(int %d, i); else if (constant instanceof Byte) byte b = (Byte) constant;formatted = String.format(byte %d, b); else if (constant instanceof Long) long l = (Long) constant;formatted = String.format(long %d, l); else if (constant instanceof Double) double d = (Double) constant;formatted = S
21、tring.format(double %f, d); else if (constant instanceof String) String s = (String) constant;formatted = String.format(String %s, s);Project AmberJEP 305: Pattern Matching for instanceofString formatted = switch (constant) case Integer i - String.format(int %d, i);case Byte b - String.format(byte %
22、d, b); case Long l - String.format(long %d, l);case Double d - String.format(double %f, d); case String s - String.format(String %s, s);/ Short, Boolean, etc default - unknown;Java SE 13Improving productivity, performance and scalability(JEP 353) Reimplement the Legacy Socket API: Reimplements the L
23、egacy Socket API to be easier to maintain, debug and prepare for user-mode threads, also known as fibers (Project Loom).Java SE 13(JEP 353) Reimplement the Legacy Socket APIThe new implementation, NioSocketImpl, is a drop-in replacement for PlainSocketImpl.Replaces the underlying implementation used
24、 by the existing .Socket and .ServerSocket APIs with a simpler and more modern implementation that is easy to maintain and debug.It shares the same JDK-internal infrastructure as the New I/O (NIO) implementation so it doesnt need its own native code.The new implementation is about the same or 1-3% b
25、etter than the old implementation on the socket read/write tests.The old implementation will remain in the JDK and a system property will be introduced to configure the JDK to use the old implementation.-D.usePlainSocketImplJava SE 13(JEP 353) Reimplement the Legacy Socket APIThe new implementation
26、will be easy to adapt to work with user-mode threads,a.k.a. fibers, currently being explored in Project Loom.Project LoomEasier and more scalable concurrency modelMaking blocking calls virtually free“Fibers” (lightweight threads) and continuationsMillions of fibers can be spawned in a single JVM ins
27、tanceMakingconcurrencysimpleagainProject LoomWhy?Simple (blocking / synchronous), But less scalable code (with threads)ANDComplex, non-legacy-interoperable, But scalable code (asynchronous)Project LoomWhy?Project LoomcomputationA continuation is a program object representing a that may be suspended
28、and resumedas aContinuation is implemented in the HotSpot VM, lower level constructTBD on whether API to Continuations will be exposedProject Loomby theA Fiber is light weight or user mode thread, scheduled Java virtual machine, not the operating systemA fiber wraps a task in a continuationThe conti
29、nuation yields when the task need to blockThe continuation is continued when the task is ready to continueScheduler executes tasks on a pool of carrier threadjava.util.concurrent.Executor in the current prototypeDefault/build-in scheduler is a ForkJoinPoolfiber = continuation + schedulerProject Loom
30、Path(/rest)public class SleepService GETPath(sleep)Produces(MediaType.APPLICATION_JSON)public String sleep(QueryParam(millis) long millis) if (millis = 0) millis = 100;try Thread.sleep(millis); catch (InterruptedException e) return millis: + millis + ;Project Loomthreads=100, rate=1000Project Loomfi
31、ber=unlimited, rate=1000Project LoomThreadPool pool; if (useThreads) System.out.println(Using thread pool, #threads= + nthreads); pool = new QueuedThreadPool(nthreads, Math.min(nthreads, 10); else System.out.println(Using fibers); pool = new ThreadPool() Overridepublic void execute(Runnable command)
32、 FiberScope.background().schedule(command);Project LoomThread 2KB metadata1MB stack110sFiber200300B metadata Pay-as-you-go stack?nsProject LoomStructured Concurrencythat that theyThe core concept of structured concurrency is when control splits into concurrent tasksjoin up again.If a “main task” spl
33、its into several concurrent sub-tasks scheduled to be executed in fibers then those fibers must terminate before the main task can complete.Project LoomStructured ConcurrencyCurrent prototypetry (var scope = FiberScope.open() var fiber1 = scope.schedule(task); var fiber2 = scope.schedule(task););Can
34、not exit scope until all fibers scheduled in the scope had terminatedFiber scopes can be nestedCancellationA FiberScope can be created with options that configure cancellationDeadline/TimeoutsFiberScope supports creating and entering a scope with a deadlineADBA Standardization Effort TerminatedOracl
35、e will not work on ADBA (Asynchronous Database Access)No work on the APINo work on the reference implementationNo work on any async database access Java standardThe API and implementation are GPL, others can continue if they wishLoom is the Future of Scalable JavaSequential code is simpler but waste
36、s resources on threadsThe value of async code is scalability, but with more complexProject Loom introduces fibers, which is lightweight threads, easily millions per JVMOracle Database 20c JDBC drivers are fiber-readyThe Next Big Challenges OpportunitiesContainersPredictabilityPerformanceData optimizationHW accelerationScalabilityContinual language enhancementsInn
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 贵阳人文科技学院《风景园林制图》2023-2024学年第二学期期末试卷
- 江苏理工学院《分子生物学及分子生物学实验》2023-2024学年第二学期期末试卷
- 烟台城市科技职业学院《数据库技术(一)》2023-2024学年第二学期期末试卷
- 合肥信息技术职业学院《技术经济与企业管理》2023-2024学年第二学期期末试卷
- 广州铁路职业技术学院《电气专业外语》2023-2024学年第一学期期末试卷
- 湖北文理学院《环境管理与规划》2023-2024学年第二学期期末试卷
- 广西外国语学院《基础日语》2023-2024学年第二学期期末试卷
- 吉林建筑大学《能源动力与轮机工程概论》2023-2024学年第一学期期末试卷
- 新疆科信职业技术学院《机器视觉技术》2023-2024学年第二学期期末试卷
- 2025年副主任医师报考条件解析与备考指南
- 2022年国家义务教育质量检测练习卷1八年级音乐练习卷
- 水利工程施工组织设计技术标(完整版)
- 【中小学】校内论坛、讲坛、讲座、年会、报告会、研讨会等管理制度
- 软件详细设计说明书(例)
- DB44-T 2283-2021水利工程生态设计导则1-(高清现行)
- XX县城区新建公厕、生活垃圾中转站项目实施方案可行性研究报告
- 哈萨克斯坦铁路车站代码
- 利润分配专项审计
- 螺纹的标注-PPT课件
- 勇者斗恶龙之怪兽仙境图表资料合集(合成表技能)
- 履带式液压挖掘机挖掘机构设计
评论
0/150
提交评论