云時代的Java13技術新特性_第1頁
云時代的Java13技術新特性_第2頁
云時代的Java13技術新特性_第3頁
云時代的Java13技術新特性_第4頁
云時代的Java13技術新特性_第5頁
已閱讀5頁,還剩36頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論