Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]David Buck
?
Java SE 8の主要な機能として、Lambda(クロージャ)とデフォルト?メソッド(従来ディフェンダー?メソッドもしくはエクステンション?メソッドと呼ばれていた)があります。クロージャを言語に追加することによってアプリケーションやライブラリに新たな表現の機会が与えられましたが、実際にはどのように実装すべきなのでしょうか。Lambdaはインナー?クラスによってシンプルでかつ文法的にコンパクトになるということは広く理解されていると思います。しかし、現実にはLambdaによる記述は、Invokedynamicを使った実装によって従来のJavaとは異なったものになっています。本セッションでLambdaについて、さらに深く理解してください。
Consideration points for migrating from older pre-J2EE, J2EE 1.2-1.4, Java EE 5-6 to EE 7, and migration points especially for web front-end systems and back-ends. JSP to JSF, EJB to CDI with migration procedure details. 狠狠撸 materials on Java Day Tokyo 2016.
The document discusses seven points for applying Java EE 7:
1. Select a Java EE 7 compliant application server like GlassFish or WildFly. Consider factors like commercial support needs.
2. Use a modern IDE like Eclipse, NetBeans or IntelliJ IDEA to build projects with Maven.
3. Apply JSF for the front-end framework and use Facelets for mark-up.
4. Apply EJBs for the back-end framework to benefit from features like automatic transactions.
5. Consider using RMI-IIOP for heavy transactions or WebSockets for lightweight and faster systems.
6. Apply JPA for database persistence.
7. Consider Java EE 8 for
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]David Buck
?
Java SE 8の主要な機能として、Lambda(クロージャ)とデフォルト?メソッド(従来ディフェンダー?メソッドもしくはエクステンション?メソッドと呼ばれていた)があります。クロージャを言語に追加することによってアプリケーションやライブラリに新たな表現の機会が与えられましたが、実際にはどのように実装すべきなのでしょうか。Lambdaはインナー?クラスによってシンプルでかつ文法的にコンパクトになるということは広く理解されていると思います。しかし、現実にはLambdaによる記述は、Invokedynamicを使った実装によって従来のJavaとは異なったものになっています。本セッションでLambdaについて、さらに深く理解してください。
Consideration points for migrating from older pre-J2EE, J2EE 1.2-1.4, Java EE 5-6 to EE 7, and migration points especially for web front-end systems and back-ends. JSP to JSF, EJB to CDI with migration procedure details. 狠狠撸 materials on Java Day Tokyo 2016.
The document discusses seven points for applying Java EE 7:
1. Select a Java EE 7 compliant application server like GlassFish or WildFly. Consider factors like commercial support needs.
2. Use a modern IDE like Eclipse, NetBeans or IntelliJ IDEA to build projects with Maven.
3. Apply JSF for the front-end framework and use Facelets for mark-up.
4. Apply EJBs for the back-end framework to benefit from features like automatic transactions.
5. Consider using RMI-IIOP for heavy transactions or WebSockets for lightweight and faster systems.
6. Apply JPA for database persistence.
7. Consider Java EE 8 for
The document appears to be a schedule and information for JavaOne 2016, which was held in San Francisco. The summary includes:
- JavaOne 2016 was held from September 18-22 in Moscone North in San Francisco.
- The schedule lists the daily events and sessions happening from 8:30am to 9pm each day, including keynotes, technical sessions, and social events.
- Some of the keynote speakers listed include Sharat Chander, Michael Greene, and Brian Goetz. Social events include receptions, a community appreciation event, and a concert at AT&T Park.
This document discusses different levels or stages and provides a hyperlink to a website with information about those levels. It also lists several references to the same case study from 2013 about implementing Kanban in an enterprise setting, written by Mattias Skarin. The document focuses on stages or levels and cites the same case study multiple times.
The document shows an example of converting an external iteration over a list using a for loop into an internal iteration using Java streams. First, a for loop is used to iterate over a list of numbers and add each number multiplied by 2 to a new list. Then, this is rewritten using streams to map each number by multiplying it by 2 and collecting the results into a new list, eliminating the need for an anonymous class.
15. JAX-RS2.1
非同期クライアント: rx()によるCompletationState取得
// Aの問い合わせ (非同期)
WebTarget targetA = Client.newClient().target(...);
CompletionStage<User> a = target1.request().resolveTemplate(“id”, 1)
.rx().get(User.class);
// Bの問い合わせ (非同期)
CompletionState<Product> b = targetB.request().resolveTemplate(“id”, 1)
.rx().get(Product.class);
// AとBの結果を組み合わせて、Cに問い合わせ (非同期)
CompletionState<String> c = a.thenCombine(b, (user, product) ->
targetC.request()
.resolveTemplate(“user”,user)
.resolveTemplate(“prod”,product).rx().get(...)));
// 最終的な結果の取得
c.join();
a
b
c 最終的な結果
16. JAX-RS2.1
非同期クライアント: rx()によるCompletationState取得
// Aの問い合わせ (非同期)
WebTarget targetA = Client.newClient().target(...);
CompletionStage<User> a = target1.request().resolveTemplate(“id”, 1)
.rx().get(User.class);
// Bの問い合わせ (非同期)
CompletionState<Product> b = targetB.request().resolveTemplate(“id”, 1)
.rx().get(Product.class);
// AとBの結果を組み合わせて、Cに問い合わせ (非同期)
CompletionState<String> c = a.thenCombine(b, (user, product) ->
targetC.request()
.resolveTemplate(“user”,user)
.resolveTemplate(“prod”,product).rx().get(...)));
// 最終的な結果の取得
c.join();
a
b
c 最終的な結果
17. JAX-RS2.1
非同期クライアント: アノテーションによる依存性制御
class DeclarativeRxHandler {
@FinalResult
public String getC(
@PartialResult(“A”) String a, @PartialResult(“B”) String b) {
return a;
}
@PartialResult(“A”)
public CompletableFuture<String> getA() {...}
@PartialResult(“B”)
public CompletableFuture<String> getB() {...}
}
A
B
C 最終的な結果
18. JAX-RS2.1
ノンブロッキング I/O - 背景
? 不安定/遅いネットワークからファイルアップロード
? CPUは別スレッドに割当てられても、メモリは1MB消費し続ける
@Path(“/upload”)
public class FileUploadResource {
@POST @Consumes(MediaType.MULTIPART_FORM_DATA)
public void upload(@FormDataParam(“file”) InputStream input, ...) {
byte[] buf = new byte[1024];
int readed;
try {
while ((readed = input.read(buf)) != -1) {
// write file ...
} catch (IOException e) {...}
}
データが来るまでブロック
(64bitJVM)
19. @POST @Consumes(MediaType.APPLICATION_OCTET_STREAM)
public void upload(@QueryParam(“path”) String path,
@Context request, @Suspend AsyncResponse response) {
FileOutputStream out = new FileOutputStream(tmpdir);
byte[] buf = new byte[1024];
request.entity(input -> {
try {
if (input.isFinished()) {
// データ読み込み完了
out.close();
response.resume(“Upload Completed”);
} else {
final int n = input.read(buffer);
out.write(buffer, 0, n);
}
} catch (IOException e) {...}
}
}
JAX-RS2.1
ノンブロッキング I/O - JavaOneで紹介されていたアイディア
20. @POST @Consumes(MediaType.APPLICATION_OCTET_STREAM)
public void upload(@QueryParam(“path”) String path,
@Context request, @Suspend AsyncResponse response) {
FileOutputStream out = new FileOutputStream(tmpdir);
byte[] buf = new byte[1024];
request.entity(input -> {
try {
if (input.isFinished()) {
// データ読み込み完了
out.close();
response.resume(“Upload Completed”);
} else {
final int n = input.read(buffer);
out.write(buffer, 0, n);
}
} catch (IOException e) {...}
}
}
ブロックしない
読込可能データの発生毎に
繰り返しコールバックされる?
JAX-RS2.1
ノンブロッキング I/O - JavaOneで紹介されていたアイディア
33. JPA2.2
検討中の主な項目
? Java SE 8対応
? Date and Time API への対応
? @NamedQueryのRepeatableアノテーション対応
? スクロール機能の標準化
? 例: org.hibernate.ScrollableResults
34. JPA2.2
スクロール機能の標準化 - getStreamResult()
Query q = em.createQuery(“select e from Employee e”);
// OutOfMemoryError ??
List<Employee> employees = q.getResultList();
// 少ないJavaヒープメモリで動作
int total = q.getStreamResult().collect(
Collectors.summingInt(Employee::getSalary));
35. Java EE 8 スケジュール
Java EE 8 & GlassFish5リリースは2017上半期予定
? 2015 Q4 Early Draft
? 2016 Q1 Public Review
? 2016 Q4 Proposed Final Draft
? 2017年上半期 Final 予定