SlideShare a Scribd company logo
Java 엿새째
TmaxSoft R&D Center
1
113년	 10월	 22일	 화
자바 교육 계획
1일 : Language, String,
ClassLoader, Proxy
2일 : GC, Collections
3일 : Thread, Java Memory
Model
4일 : AQS, ForkJoin,
Concurrent Utils
5일 : IO, Generics, Annotation,
RMI
6일 : Unsafe, Lambda (Java 8)
2
내겐 바스켓만 보여 (Flow 상태)
213년	 10월	 22일	 화
오늘 내용
sun.misc.Unsafe
Lambda (Java 8)
3
313년	 10월	 22일	 화
sun.misc.Unsafe
4
413년	 10월	 22일	 화
sun.misc.Unsafe
5
A collection of methods for performing low-level, unsafe operations
park, unpark
direct memory manipulation
provide wrappers for malloc, realloc, free, memset, memcpy
(not Java Heap)
direct object memory manipulation
CAS operations : compareAndSwap
defineClass, defineAnonymousClass
513년	 10월	 22일	 화
Java is not safe with Unsafe
6
can easily corrupt memory
fast serialization
super array (non-Java heap)
allocateMemory(long size)
can cause JVM crash
613년	 10월	 22일	 화
Lambda
7
The	
  issue	
  being	
  debated	
  is	
  not	
  whether	
  closures	
  are	
  a	
  
good	
  idea	
  -­‐	
  because	
  they	
  clearly	
  are	
  -­‐	
  but	
  whether	
  
the	
  benefits	
  of	
  retrofi7ng	
  the	
  Java	
  language	
  with	
  
closures	
  are	
  worth	
  the	
  costs.
-­‐	
  Brian	
  Goetz
713년	 10월	 22일	 화
Functional Programming
8
lambda
anonymous function with a single argument
closure
a block of code that may contain free (unbound)
variables
currying
handling multiple argument function with lambda
function
813년	 10월	 22일	 화
Java 8 Lambda Expression
SAM (single abstract method) of an interface
Java lambda expression
a list of formal parameters and a body—an expression
or block—expressed in terms of those parameters
e.g,
s -> s.toUpperCase()
(int a, int b) -> a + b
9
913년	 10월	 22일	 화
Method Reference expression
method reference : refer to a method without invoking it
System::getProperty
"abc"::length
constructor reference : refer to a constructor without creating
a new instance of the named class or array type
ArrayList::new
int[]::new
e.g, Arrays.sort(myIntegerArray, Integer::compare)
10
1013년	 10월	 22일	 화
Java 8 Closure
For both lambda bodies and inner classes, local
variables in the enclosing context can only be
referenced if they are final or effectively final.
A variable is effectively final if it is never assigned to
after its initialization.
11
1113년	 10월	 22일	 화
Java 8 Currying
Currying :A technique of transforming a multi-argument
function in such a way that it can be called as a chain
of functions, each with a single argument.
12
1213년	 10월	 22일	 화
New Object-oriented feature
mixin
a class which contains a combination of methods
from other classes.
can also be viewed as an interface with implemented
methods.
Mixins encourage code reuse and avoid well-known
pathologies associated with multiple inheritance.
13
1313년	 10월	 22일	 화
Java 8 Default Method
Java’s language addition of mixin-like thing
provides a default implementation for any class that
implements the interface without overriding the
method.
allows new functionality to be added to existing (and
perhaps already widely-distributed) interfaces.
More generally, it provides a mechanism for multiple
inheritance of behavior.
14
1413년	 10월	 22일	 화
Java 8 Changes to Interface
Now, interface method can be default, static and
abstract
all the non-default, non-static methods in the
interface are abstract as before
Default methods of super-interface can be accessed
<InterfaceName>.super.<methodName>()
15
1513년	 10월	 22일	 화
Java 8 Project Lambda
Language Changes
Still, No Function Type
Functional Interface
Default Method
Streams
invokeDynamic
java.util.Spliterator
16
1613년	 10월	 22일	 화
Java Lambda ABC
@interface java.lang.FunctionalInterface
Just a hint for compiler (compile error if does not have
SAM)
any interface which has SAM is functional interface
package java.util.function
lambda function does not create additional classes unlike
anonymous inner classes
it creates a private static lambda method
17
1713년	 10월	 22일	 화
Streams
handle aggregate operations DECLARATIVELY
stream pipeline
1 source : collection, array, generator ftn, IO, ...
0 or more intermediate operations : filter, map, ...
1 terminal operation : forEach, reduce, sum, ...
18
1813년	 10월	 22일	 화
Stages of Streams
txns.stream()
.filter(txn -> txn.getBuyer().getAge() >= 65)
.map(txn -> txn.getSeller())
.distinct()
.sort(comparing(seller -> seller.getName()))
.forEach(seller ->
System.out.println(seller.getName());
19
source
intermediate
intermediate
intermediate
intermediate
terminal
intermediate ops just setup pipeline
and returns new stream
1913년	 10월	 22일	 화
Parallel Streams
A stream pipeline can be created with an orientation of either
serial or parallel
Parallelism may be faster but introduces non-determinism
Internally uses fork-join framework
Collection c = ...;
List r1 = c.stream().map(...).collect(toList());
List r2 = c.parallelStream().map(...).collect(toList());
20
2013년	 10월	 22일	 화
Parallel Streams
21
2113년	 10월	 22일	 화
MethodHandle
java.lang.invoke 패키지
can store references to methods in the constant pool, load
with LDC (load constant)
can obtain a method handle for any method (or field access)
But
MethodHandle invocation performance is not good
Lambda is language level method, MethodHandle is VM
level method
22
2213년	 10월	 22일	 화
Lambda Invocation
desugar implementation method
private static boolean lambda$1(int minAge, Person p) { ... }
lambda metafactory에 MethodHandle argument로 전달
invokeDynamic 호출
Predicate $p = invokedynamic[bootstrap=LambdaMetaFactory, ... ]
moving more work from static compiler to runtime
performance
linkage, capture 비용은 inner class보다 싸지만 invoke 비용은 비싸다!
23
2313년	 10월	 22일	 화
invokeDynamic
invokeStatic
System.currentTimeMillis(), Math.log(1.0)
invokeVirtual
"hello".toUpperCase(), System.out.println()
invokeInterface
myList.add("happy happy"), myRunnable.run()
invokeSpecial (constructor or super call)
new ArrayList(), super.equals(other)
성능 비교
invokeStatic (2.7배) >> invokeDynamic (12.6배) >> reflection
24
2413년	 10월	 22일	 화
다음 시간 예정
JEUS Web Engine
25
여러분의 전성시대는 언제였나요?
2513년	 10월	 22일	 화

More Related Content

PPTX
Apache Kafka, HDFS, Accumulo and more on Mesos
PPTX
Introduction To Apache Mesos
PPTX
Openstack study-nova-02
PDF
Kubernetes Walk Through from Technical View
PDF
From swarm to swam-mode in the CERN container service
PDF
MongoDB as Message Queue
PDF
From Kubernetes to OpenStack in Sydney
PDF
Orchestrating Redis & K8s Operators
Apache Kafka, HDFS, Accumulo and more on Mesos
Introduction To Apache Mesos
Openstack study-nova-02
Kubernetes Walk Through from Technical View
From swarm to swam-mode in the CERN container service
MongoDB as Message Queue
From Kubernetes to OpenStack in Sydney
Orchestrating Redis & K8s Operators

What's hot (20)

PPTX
Kubernetes #6 advanced scheduling
PPTX
Kubernetes #2 monitoring
PDF
ARCHITECTING TENANT BASED QOS IN MULTI-TENANT CLOUD PLATFORMS
PDF
Monitoring with Prometheus
PPTX
Apache Mesos
PDF
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
PPTX
Introduction to Apache Mesos
PDF
[245] presto 내부구조 파헤치기
PDF
Getting Started Hacking OpenNebula - Fosdem-2013
PPTX
Orchestration tool roundup - OpenStack Israel summit - kubernetes vs. docker...
PPTX
Introduction to Apache ZooKeeper
PPTX
Making Distributed Data Persistent Services Elastic (Without Losing All Your ...
PDF
[OpenInfra Days Korea 2018] Day 2 - E6 - OpenInfra monitoring with Prometheus
PDF
[214]유연하고 확장성 있는 빅데이터 처리
PDF
OSv at Cassandra Summit
PDF
Building and deploying a distributed application with Docker, Mesos and Marathon
PDF
Deploying Docker Containers at Scale with Mesos and Marathon
PPTX
Distributed Tests on Pulsar with Fallout - Pulsar Summit NA 2021
PDF
Docker volume-isolator-in-mesos
PPT
On MongoDB backup
Kubernetes #6 advanced scheduling
Kubernetes #2 monitoring
ARCHITECTING TENANT BASED QOS IN MULTI-TENANT CLOUD PLATFORMS
Monitoring with Prometheus
Apache Mesos
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
Introduction to Apache Mesos
[245] presto 내부구조 파헤치기
Getting Started Hacking OpenNebula - Fosdem-2013
Orchestration tool roundup - OpenStack Israel summit - kubernetes vs. docker...
Introduction to Apache ZooKeeper
Making Distributed Data Persistent Services Elastic (Without Losing All Your ...
[OpenInfra Days Korea 2018] Day 2 - E6 - OpenInfra monitoring with Prometheus
[214]유연하고 확장성 있는 빅데이터 처리
OSv at Cassandra Summit
Building and deploying a distributed application with Docker, Mesos and Marathon
Deploying Docker Containers at Scale with Mesos and Marathon
Distributed Tests on Pulsar with Fallout - Pulsar Summit NA 2021
Docker volume-isolator-in-mesos
On MongoDB backup
Ad

Similar to Java 8 고급 (6/6) (20)

DOCX
Java mcq
PPT
Scala Talk at FOSDEM 2009
PPT
Java programing considering performance
PPT
whats new in java 8
PPT
Collections and generic class
DOC
24 collections framework interview questions
PDF
Java 8 고급 (4/6)
PDF
Java Course 4: Exceptions & Collections
PPTX
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
PDF
Clojure - A practical LISP for the JVM
ODP
Functional programming with Scala
PDF
Core_Java_Interview.pdf
PDF
Clojure for Java developers
PDF
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
DOC
Java interview questions
DOCX
Jist of Java
DOCX
JAVA CONCEPTS AND PRACTICES
PPTX
Java 10, Java 11 and beyond
PPTX
GJIMT BCA P4UGCA1932U3L6.pptx
Java mcq
Scala Talk at FOSDEM 2009
Java programing considering performance
whats new in java 8
Collections and generic class
24 collections framework interview questions
Java 8 고급 (4/6)
Java Course 4: Exceptions & Collections
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
Clojure - A practical LISP for the JVM
Functional programming with Scala
Core_Java_Interview.pdf
Clojure for Java developers
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Java interview questions
Jist of Java
JAVA CONCEPTS AND PRACTICES
Java 10, Java 11 and beyond
GJIMT BCA P4UGCA1932U3L6.pptx
Ad

More from Kyung Koo Yoon (12)

PDF
Kubernetes
PDF
Java 8 고급 (5/6)
PDF
Java 8 고급 (3/6)
PDF
Java 8 고급 (2/6)
PDF
Java 8 고급 (1/6)
PDF
Spring Framework - Inversion of Control Container
PDF
Smart software engineer
PPT
Lecture on Java Concurrency Day 3 on Feb 11, 2009.
PPT
Lecture on Java Concurrency Day 2 on Feb 4, 2009.
PPT
Lecture on Java Concurrency Day 4 on Feb 18, 2009.
PPT
Lecture on Java Concurrency Day 1 on Jan 21, 2009.
PPTX
창의와 열정, 소프트웨어 엔지니어
Kubernetes
Java 8 고급 (5/6)
Java 8 고급 (3/6)
Java 8 고급 (2/6)
Java 8 고급 (1/6)
Spring Framework - Inversion of Control Container
Smart software engineer
Lecture on Java Concurrency Day 3 on Feb 11, 2009.
Lecture on Java Concurrency Day 2 on Feb 4, 2009.
Lecture on Java Concurrency Day 4 on Feb 18, 2009.
Lecture on Java Concurrency Day 1 on Jan 21, 2009.
창의와 열정, 소프트웨어 엔지니어

Recently uploaded (20)

PDF
Topaz Photo AI Crack New Download (Latest 2025)
PDF
Types of Token_ From Utility to Security.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
"Secure File Sharing Solutions on AWS".pptx
PPTX
Cybersecurity: Protecting the Digital World
PDF
STL Containers in C++ : Sequence Container : Vector
PDF
DNT Brochure 2025 – ISV Solutions @ D365
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Time Tracking Features That Teams and Organizations Actually Need
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PPTX
chapter 5 systemdesign2008.pptx for cimputer science students
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
Custom Software Development Services.pptx.pptx
Topaz Photo AI Crack New Download (Latest 2025)
Types of Token_ From Utility to Security.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
"Secure File Sharing Solutions on AWS".pptx
Cybersecurity: Protecting the Digital World
STL Containers in C++ : Sequence Container : Vector
DNT Brochure 2025 – ISV Solutions @ D365
How to Use SharePoint as an ISO-Compliant Document Management System
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Time Tracking Features That Teams and Organizations Actually Need
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Advanced SystemCare Ultimate Crack + Portable (2025)
Oracle Fusion HCM Cloud Demo for Beginners
chapter 5 systemdesign2008.pptx for cimputer science students
iTop VPN Crack Latest Version Full Key 2025
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
How Tridens DevSecOps Ensures Compliance, Security, and Agility
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Custom Software Development Services.pptx.pptx

Java 8 고급 (6/6)

  • 1. Java 엿새째 TmaxSoft R&D Center 1 113년 10월 22일 화
  • 2. 자바 교육 계획 1일 : Language, String, ClassLoader, Proxy 2일 : GC, Collections 3일 : Thread, Java Memory Model 4일 : AQS, ForkJoin, Concurrent Utils 5일 : IO, Generics, Annotation, RMI 6일 : Unsafe, Lambda (Java 8) 2 내겐 바스켓만 보여 (Flow 상태) 213년 10월 22일 화
  • 3. 오늘 내용 sun.misc.Unsafe Lambda (Java 8) 3 313년 10월 22일 화
  • 5. sun.misc.Unsafe 5 A collection of methods for performing low-level, unsafe operations park, unpark direct memory manipulation provide wrappers for malloc, realloc, free, memset, memcpy (not Java Heap) direct object memory manipulation CAS operations : compareAndSwap defineClass, defineAnonymousClass 513년 10월 22일 화
  • 6. Java is not safe with Unsafe 6 can easily corrupt memory fast serialization super array (non-Java heap) allocateMemory(long size) can cause JVM crash 613년 10월 22일 화
  • 7. Lambda 7 The  issue  being  debated  is  not  whether  closures  are  a   good  idea  -­‐  because  they  clearly  are  -­‐  but  whether   the  benefits  of  retrofi7ng  the  Java  language  with   closures  are  worth  the  costs. -­‐  Brian  Goetz 713년 10월 22일 화
  • 8. Functional Programming 8 lambda anonymous function with a single argument closure a block of code that may contain free (unbound) variables currying handling multiple argument function with lambda function 813년 10월 22일 화
  • 9. Java 8 Lambda Expression SAM (single abstract method) of an interface Java lambda expression a list of formal parameters and a body—an expression or block—expressed in terms of those parameters e.g, s -> s.toUpperCase() (int a, int b) -> a + b 9 913년 10월 22일 화
  • 10. Method Reference expression method reference : refer to a method without invoking it System::getProperty "abc"::length constructor reference : refer to a constructor without creating a new instance of the named class or array type ArrayList::new int[]::new e.g, Arrays.sort(myIntegerArray, Integer::compare) 10 1013년 10월 22일 화
  • 11. Java 8 Closure For both lambda bodies and inner classes, local variables in the enclosing context can only be referenced if they are final or effectively final. A variable is effectively final if it is never assigned to after its initialization. 11 1113년 10월 22일 화
  • 12. Java 8 Currying Currying :A technique of transforming a multi-argument function in such a way that it can be called as a chain of functions, each with a single argument. 12 1213년 10월 22일 화
  • 13. New Object-oriented feature mixin a class which contains a combination of methods from other classes. can also be viewed as an interface with implemented methods. Mixins encourage code reuse and avoid well-known pathologies associated with multiple inheritance. 13 1313년 10월 22일 화
  • 14. Java 8 Default Method Java’s language addition of mixin-like thing provides a default implementation for any class that implements the interface without overriding the method. allows new functionality to be added to existing (and perhaps already widely-distributed) interfaces. More generally, it provides a mechanism for multiple inheritance of behavior. 14 1413년 10월 22일 화
  • 15. Java 8 Changes to Interface Now, interface method can be default, static and abstract all the non-default, non-static methods in the interface are abstract as before Default methods of super-interface can be accessed <InterfaceName>.super.<methodName>() 15 1513년 10월 22일 화
  • 16. Java 8 Project Lambda Language Changes Still, No Function Type Functional Interface Default Method Streams invokeDynamic java.util.Spliterator 16 1613년 10월 22일 화
  • 17. Java Lambda ABC @interface java.lang.FunctionalInterface Just a hint for compiler (compile error if does not have SAM) any interface which has SAM is functional interface package java.util.function lambda function does not create additional classes unlike anonymous inner classes it creates a private static lambda method 17 1713년 10월 22일 화
  • 18. Streams handle aggregate operations DECLARATIVELY stream pipeline 1 source : collection, array, generator ftn, IO, ... 0 or more intermediate operations : filter, map, ... 1 terminal operation : forEach, reduce, sum, ... 18 1813년 10월 22일 화
  • 19. Stages of Streams txns.stream() .filter(txn -> txn.getBuyer().getAge() >= 65) .map(txn -> txn.getSeller()) .distinct() .sort(comparing(seller -> seller.getName())) .forEach(seller -> System.out.println(seller.getName()); 19 source intermediate intermediate intermediate intermediate terminal intermediate ops just setup pipeline and returns new stream 1913년 10월 22일 화
  • 20. Parallel Streams A stream pipeline can be created with an orientation of either serial or parallel Parallelism may be faster but introduces non-determinism Internally uses fork-join framework Collection c = ...; List r1 = c.stream().map(...).collect(toList()); List r2 = c.parallelStream().map(...).collect(toList()); 20 2013년 10월 22일 화
  • 22. MethodHandle java.lang.invoke 패키지 can store references to methods in the constant pool, load with LDC (load constant) can obtain a method handle for any method (or field access) But MethodHandle invocation performance is not good Lambda is language level method, MethodHandle is VM level method 22 2213년 10월 22일 화
  • 23. Lambda Invocation desugar implementation method private static boolean lambda$1(int minAge, Person p) { ... } lambda metafactory에 MethodHandle argument로 전달 invokeDynamic 호출 Predicate $p = invokedynamic[bootstrap=LambdaMetaFactory, ... ] moving more work from static compiler to runtime performance linkage, capture 비용은 inner class보다 싸지만 invoke 비용은 비싸다! 23 2313년 10월 22일 화
  • 24. invokeDynamic invokeStatic System.currentTimeMillis(), Math.log(1.0) invokeVirtual "hello".toUpperCase(), System.out.println() invokeInterface myList.add("happy happy"), myRunnable.run() invokeSpecial (constructor or super call) new ArrayList(), super.equals(other) 성능 비교 invokeStatic (2.7배) >> invokeDynamic (12.6배) >> reflection 24 2413년 10월 22일 화
  • 25. 다음 시간 예정 JEUS Web Engine 25 여러분의 전성시대는 언제였나요? 2513년 10월 22일 화