SlideShare a Scribd company logo
Evolving Java for the
Microservice and Serverless Era
About Me
• Graeme Rocher
• Creator of Grails and Micronaut
• Principal Engineer at Object Computing
• 2018 Oracle Groundbreaker Award Winner
• Java Champion
Agenda
• Challenges Facing Java
• Introduction to Micronaut
• Micronaut's Approach to Solving The Problems
• Demos!
Java and Serverless
• Challenges to using Java in
Serverless / Microservices scenarios
• Existing Tools and Frameworks Not
Optimized for Cold Starts / Low
Memory
• Go, Node etc. better in this regards
• Tim Bray (Amazon/AWS) and others
not recommending Java
https://youtu.be/IPOvrK3S3gQ?t=1109
Java's Problems for
Frameworks
• Limited Annotation API
• Type Erasure
• Slow Reflection
• Reflective Data Caches
• Classpath Scanning
• Slow Dynamic Class Loading
Java's Problems
• Greatly Exaggerated (Java has been
dead forever)
• Java can be Fast! (see Android and
Micronaut)
• However Most Existing Tools are
based around
• Reflection
• Runtime Proxies
• Runtime Byte Code Generation
(bytebuddy/cglib)
Why is Reflection a Problem?
• Today the JDK is OpenJDK!
• Just take a look...
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/
share/classes/java/lang/Class.java#l2471
• All Reflective data initialized on first access and held in soft
references (yes every field, method etc.)
• Won't be GC'ed until your application is low on memory!
Avoid Reflection!
• Reflection usages increases memory
usage
• Using reflection relatively slow
• Problem is most modern server-side
frameworks and specifications
are built on reflection
• Some of the Jarkarta specifications
even mandate reflection
Just Like The
Android World
• The Android Community already
solved the problem
• Ahead of Time Compilation used
extensively
• Google Dagger 2.x for DI
• Most Android Frameworks avoid
reflection to
avoid paying the memory /
performance cost
Micronaut
• A Microservices and Serverless
Focused framework (hence the
branding)
• Also a Complete Application
Framework for any type of
Application
• Dependency Injection, Aspect
Oriented Programming (AOP),
Configuration Management,
Bean Introspection and more..
With Micronaut You
Can Build
• Microservices
• Serverless Applications
• Message-Driven Applications with
Kafka/Rabbit
• CLI Applications
• Even Android Applications
• Anything with
static void main(String..args)
So What is
Micronaut? Really?
• An Application Framework for the
Future
• Reflection Free, Runtime Proxy Free,
No Dynamic Classloading (in 1.1)
• Ahead of Time (AOT) Compilation
AOT APIs
• ... oh and let's you build
Microservices
Micronaut and
GraalVM
• A New Universal Virtual Machine
from Oracle
• Features a native-image Tool
• Converts Java -> native machine
code using AOT
• Works well with Micronaut
• Startup time 20ms and Memory
Consumption 18MB!
http://www.graalvm.org
Micronaut's Solutions
Problem Solution
Limited Annotation API Precomputed AnnotationMetadata
Type Erasure Precomputed Argument Interface
Slow Reflection Eliminate Reflection
Reflective Data Caches Zero Data Caches
Classpath Scanning No Classpath Scanning
Slow Dynamic Class Loading No Dynamic Class Loaders
DEMOMicronaut Bean Introspection
@Introspected
@Introspected
class MyBean {
private List<String> names; //getter/setter omitted
}
• AOT Reflection-free replacement for
java.beans.Introspector
• Set/get bean properties, create instances
• Includes AnnotationMetadata
AnnotationMetadata
AnnotationMetadata metadata = BeanIntrospection.getIntrospection(MyBean.class)
.getAnnotationMetadata();
if (metadata.hasStereotype(SomeAnnotation.class)) {
// do stuff
}
• AOT Computed / Merged Annotation Replacement for
Reflection based API
• Includes knowledge of meta-
AnnotationMetadata
Why?
• All the Nullable annotations!!!
• javax.annotation.Nullable (Java)
• org.jetbrains.annotations.
Nullable (Kotlin)
• edu.umd.cs.findbugs.
annotations.Nullable (Spotbugs)
• org.springframework.
lang.Nullable (Spring)
Argument
BeanProperty<MyBean, List> property =
introspection.getRequireProperty("names", List.class);
// returns an Argument with an underlying type of String
Optional<Argument> typeVariable = property.asArgument()
.getFirstTypeVariable()
• AOT Computed Generic Type information
• No type erasure / crazly reflection logic to get the type
argument
Argument
Why?
• You think resolving generic types in
simple?
https://github.com/spring-projects/
spring-framework/blob/master/spring-
core/src/main/java/org/
springframework/core/
ResolvableType.java
DEMOMicronaut Dependency Injection
BeanDefinition
ApplicationContext ctx = ApplicationContext.run();
BeanDefinition<MyBean> definition
= ctx.getBeanDefinition(MyBean.class);
• Contains precomputed AnnotationMetadata and generic
type info
• Used by ApplicationContext to instantiate beans
BeanDefinition
• Bean definitions produced for any @Singleton
• Constructor injection used by default
• Use @Factory for beans you cannot annotate
• Compliant with javax.inject spec and TCK
@ConfigurationProperties
Type Safe Configuration
@ConfigurationProperties("example")
class ExampleConfiguration {
// getters/setters omitted
private String name;
}
ApplicationContext context = ApplicationContext.run("example.name":"Demo");
FooConfiguration config = context.getBean(FooConfiguration);
assert config.name == 'Demo'
@Requires
Conditional Beans Made Easy
@Requires(property="example.enabled")
@Requires(beans=DataSource.class)
@Requires(missingBeans=Example.class)
@Singleton
class DefaultExampleBean implements Example {
...
}
ApplicationContext context = ApplicationContext.run("example.enabled":"true")
Example example = context.getBean(Example)
@Executable
@Scheduled(fixedRate = "5m") // @Scheduled annotated with @Executable
void everyFiveMinutes() {
messageService.sendMessage("Hello World");
}
• Common Stereotype annotation
• Identifies where framework invokes your code
• Produces reflection-free ExectubleMethod instance
@ExecutableMethodProcessor
public class ScheduledMethodProcessor
implements ExecutableMethodProcessor<Scheduled> {
public void process(BeanDefinition<?> beanDefinition,
ExecutableMethod<?, ?> method) {
// do stuff with the bean
}
}
• Processes only methods annotated by type argument
• In the above case setting up a scheduled job
DEMOMicronaut AOP
@Around
@Retryable // @Retryable is annotated with @Around
void invokeMe() {
// do stuff
}
• Intercepts a method with a MethodInterceptor
• No runtime proxies (compile time proxies) or reflection
needed
• No FancyProxyFactoryBean or containers needed!
@Around
@Around
@Type(DefaultRetryInterceptor.class)
public @interface Retryable {
// annotation attributes
}
• Use @Type to specify the implementation
• At compilation Micronaut applies the AOP advise
DEMOMicronaut
Micronaut Startup and Memory
Runtime Memory Startup
JDK 11 75MB 1.1s
JDK 13 75MB 900ms
JDK 13 + CDS 75MB 400ms
GraalVM Substrate 15MB 21ms
Summary
• Micronaut Provides an Awesome Set of Framework
Primitives
• Sacrifices Compilation Speed to Gain so Much More
• Solves Problems with Spring, Jakarta EE and Java in General
• Opens the Door to GraalVM Native
• Come learn more in my "Micronaut Deep Dive" talk at 6PM!
Q & A
Micronaut: Evolving Java for the Microservices and Serverless Era
Micronaut: Evolving Java for the Microservices and Serverless Era

More Related Content

What's hot

JavaEE Microservices platforms
JavaEE Microservices platformsJavaEE Microservices platforms
JavaEE Microservices platforms
Payara
 
Javantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin ToshevJavantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin Toshev
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
Ryan Cuprak
 
Javantura v4 - Security architecture of the Java platform - Martin Toshev
Javantura v4 - Security architecture of the Java platform - Martin ToshevJavantura v4 - Security architecture of the Java platform - Martin Toshev
Javantura v4 - Security architecture of the Java platform - Martin Toshev
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
Javantura v4 - The power of cloud in professional services company - Ivan Krn...Javantura v4 - The power of cloud in professional services company - Ivan Krn...
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Spring cloud for microservices architecture
Spring cloud for microservices architectureSpring cloud for microservices architecture
Spring cloud for microservices architecture
Igor Khotin
 
Deploying Elastic Java EE Microservices in the Cloud with Docker
Deploying Elastic Java EE Microservices in the Cloud with DockerDeploying Elastic Java EE Microservices in the Cloud with Docker
Deploying Elastic Java EE Microservices in the Cloud with Docker
Payara
 
Monitor Micro-service with MicroProfile metrics
Monitor Micro-service with MicroProfile metricsMonitor Micro-service with MicroProfile metrics
Monitor Micro-service with MicroProfile metrics
Rudy De Busscher
 
Javantura v4 - FreeMarker in Spring web - Marin Kalapać
Javantura v4 - FreeMarker in Spring web - Marin KalapaćJavantura v4 - FreeMarker in Spring web - Marin Kalapać
Javantura v4 - FreeMarker in Spring web - Marin Kalapać
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
High performance java ee with j cache and cdi
High performance java ee with j cache and cdiHigh performance java ee with j cache and cdi
High performance java ee with j cache and cdi
Payara
 
Secure JAX-RS
Secure JAX-RSSecure JAX-RS
Secure JAX-RS
Payara
 
Why Play Framework is fast
Why Play Framework is fastWhy Play Framework is fast
Why Play Framework is fast
Legacy Typesafe (now Lightbend)
 
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Microservices with Spring Cloud
Microservices with Spring CloudMicroservices with Spring Cloud
Microservices with Spring Cloud
Daniel Eichten
 
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip KovačekJavantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Monitoring and Tuning GlassFish
Monitoring and Tuning GlassFishMonitoring and Tuning GlassFish
Monitoring and Tuning GlassFish
C2B2 Consulting
 
Writing Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly SwarmWriting Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly Swarm
Comsysto Reply GmbH
 
Gradual migration to MicroProfile
Gradual migration to MicroProfileGradual migration to MicroProfile
Gradual migration to MicroProfile
Rudy De Busscher
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»DataArt
 
Gwt overview & getting started
Gwt overview & getting startedGwt overview & getting started
Gwt overview & getting startedBinh Bui
 

What's hot (20)

JavaEE Microservices platforms
JavaEE Microservices platformsJavaEE Microservices platforms
JavaEE Microservices platforms
 
Javantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin ToshevJavantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin Toshev
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
Javantura v4 - Security architecture of the Java platform - Martin Toshev
Javantura v4 - Security architecture of the Java platform - Martin ToshevJavantura v4 - Security architecture of the Java platform - Martin Toshev
Javantura v4 - Security architecture of the Java platform - Martin Toshev
 
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
Javantura v4 - The power of cloud in professional services company - Ivan Krn...Javantura v4 - The power of cloud in professional services company - Ivan Krn...
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
 
Spring cloud for microservices architecture
Spring cloud for microservices architectureSpring cloud for microservices architecture
Spring cloud for microservices architecture
 
Deploying Elastic Java EE Microservices in the Cloud with Docker
Deploying Elastic Java EE Microservices in the Cloud with DockerDeploying Elastic Java EE Microservices in the Cloud with Docker
Deploying Elastic Java EE Microservices in the Cloud with Docker
 
Monitor Micro-service with MicroProfile metrics
Monitor Micro-service with MicroProfile metricsMonitor Micro-service with MicroProfile metrics
Monitor Micro-service with MicroProfile metrics
 
Javantura v4 - FreeMarker in Spring web - Marin Kalapać
Javantura v4 - FreeMarker in Spring web - Marin KalapaćJavantura v4 - FreeMarker in Spring web - Marin Kalapać
Javantura v4 - FreeMarker in Spring web - Marin Kalapać
 
High performance java ee with j cache and cdi
High performance java ee with j cache and cdiHigh performance java ee with j cache and cdi
High performance java ee with j cache and cdi
 
Secure JAX-RS
Secure JAX-RSSecure JAX-RS
Secure JAX-RS
 
Why Play Framework is fast
Why Play Framework is fastWhy Play Framework is fast
Why Play Framework is fast
 
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
 
Microservices with Spring Cloud
Microservices with Spring CloudMicroservices with Spring Cloud
Microservices with Spring Cloud
 
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip KovačekJavantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
 
Monitoring and Tuning GlassFish
Monitoring and Tuning GlassFishMonitoring and Tuning GlassFish
Monitoring and Tuning GlassFish
 
Writing Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly SwarmWriting Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly Swarm
 
Gradual migration to MicroProfile
Gradual migration to MicroProfileGradual migration to MicroProfile
Gradual migration to MicroProfile
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
 
Gwt overview & getting started
Gwt overview & getting startedGwt overview & getting started
Gwt overview & getting started
 

Similar to Micronaut: Evolving Java for the Microservices and Serverless Era

Grails 4 and Micronaut at Devnexus 2019
Grails 4 and Micronaut at Devnexus 2019Grails 4 and Micronaut at Devnexus 2019
Grails 4 and Micronaut at Devnexus 2019
graemerocher
 
Byte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in JavaByte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in Java
Alex Moskvin
 
Peru JUG Micronaut & GraalVM
Peru JUG Micronaut & GraalVMPeru JUG Micronaut & GraalVM
Peru JUG Micronaut & GraalVM
Domingo Suarez Torres
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVM
Alex Birch
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
C4Media
 
How the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeHow the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java Code
Jim Gough
 
Taking Micronaut out for a spin
Taking Micronaut out for a spinTaking Micronaut out for a spin
Taking Micronaut out for a spin
Andres Almiray
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayLuka Zakrajšek
 
Simple tweaks to get the most out of your jvm
Simple tweaks to get the most out of your jvmSimple tweaks to get the most out of your jvm
Simple tweaks to get the most out of your jvm
Jamie Coleman
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
Mohit Gupta
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
Jesang Yoon
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
Speedment, Inc.
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
Malin Weiss
 
Java-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdfJava-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdf
RichHagarty
 
Integrating Microservices with Apache Camel
Integrating Microservices with Apache CamelIntegrating Microservices with Apache Camel
Integrating Microservices with Apache Camel
Christian Posta
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
Discover Quarkus and GraalVM
Discover Quarkus and GraalVMDiscover Quarkus and GraalVM
Discover Quarkus and GraalVM
Romain Schlick
 
Simple tweaks to get the most out of your JVM
Simple tweaks to get the most out of your JVMSimple tweaks to get the most out of your JVM
Simple tweaks to get the most out of your JVM
Jamie Coleman
 
Micronaut: A new way to build microservices
Micronaut: A new way to build microservicesMicronaut: A new way to build microservices
Micronaut: A new way to build microservices
Luram Archanjo
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
jyoti_lakhani
 

Similar to Micronaut: Evolving Java for the Microservices and Serverless Era (20)

Grails 4 and Micronaut at Devnexus 2019
Grails 4 and Micronaut at Devnexus 2019Grails 4 and Micronaut at Devnexus 2019
Grails 4 and Micronaut at Devnexus 2019
 
Byte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in JavaByte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in Java
 
Peru JUG Micronaut & GraalVM
Peru JUG Micronaut & GraalVMPeru JUG Micronaut & GraalVM
Peru JUG Micronaut & GraalVM
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVM
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
How the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeHow the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java Code
 
Taking Micronaut out for a spin
Taking Micronaut out for a spinTaking Micronaut out for a spin
Taking Micronaut out for a spin
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
 
Simple tweaks to get the most out of your jvm
Simple tweaks to get the most out of your jvmSimple tweaks to get the most out of your jvm
Simple tweaks to get the most out of your jvm
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
Java-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdfJava-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdf
 
Integrating Microservices with Apache Camel
Integrating Microservices with Apache CamelIntegrating Microservices with Apache Camel
Integrating Microservices with Apache Camel
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Discover Quarkus and GraalVM
Discover Quarkus and GraalVMDiscover Quarkus and GraalVM
Discover Quarkus and GraalVM
 
Simple tweaks to get the most out of your JVM
Simple tweaks to get the most out of your JVMSimple tweaks to get the most out of your JVM
Simple tweaks to get the most out of your JVM
 
Micronaut: A new way to build microservices
Micronaut: A new way to build microservicesMicronaut: A new way to build microservices
Micronaut: A new way to build microservices
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 

Recently uploaded

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 

Recently uploaded (20)

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 

Micronaut: Evolving Java for the Microservices and Serverless Era

  • 1. Evolving Java for the Microservice and Serverless Era
  • 2. About Me • Graeme Rocher • Creator of Grails and Micronaut • Principal Engineer at Object Computing • 2018 Oracle Groundbreaker Award Winner • Java Champion
  • 3. Agenda • Challenges Facing Java • Introduction to Micronaut • Micronaut's Approach to Solving The Problems • Demos!
  • 4. Java and Serverless • Challenges to using Java in Serverless / Microservices scenarios • Existing Tools and Frameworks Not Optimized for Cold Starts / Low Memory • Go, Node etc. better in this regards • Tim Bray (Amazon/AWS) and others not recommending Java https://youtu.be/IPOvrK3S3gQ?t=1109
  • 5. Java's Problems for Frameworks • Limited Annotation API • Type Erasure • Slow Reflection • Reflective Data Caches • Classpath Scanning • Slow Dynamic Class Loading
  • 6. Java's Problems • Greatly Exaggerated (Java has been dead forever) • Java can be Fast! (see Android and Micronaut) • However Most Existing Tools are based around • Reflection • Runtime Proxies • Runtime Byte Code Generation (bytebuddy/cglib)
  • 7. Why is Reflection a Problem? • Today the JDK is OpenJDK! • Just take a look... http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/ share/classes/java/lang/Class.java#l2471 • All Reflective data initialized on first access and held in soft references (yes every field, method etc.) • Won't be GC'ed until your application is low on memory!
  • 8. Avoid Reflection! • Reflection usages increases memory usage • Using reflection relatively slow • Problem is most modern server-side frameworks and specifications are built on reflection • Some of the Jarkarta specifications even mandate reflection
  • 9. Just Like The Android World • The Android Community already solved the problem • Ahead of Time Compilation used extensively • Google Dagger 2.x for DI • Most Android Frameworks avoid reflection to avoid paying the memory / performance cost
  • 10. Micronaut • A Microservices and Serverless Focused framework (hence the branding) • Also a Complete Application Framework for any type of Application • Dependency Injection, Aspect Oriented Programming (AOP), Configuration Management, Bean Introspection and more..
  • 11. With Micronaut You Can Build • Microservices • Serverless Applications • Message-Driven Applications with Kafka/Rabbit • CLI Applications • Even Android Applications • Anything with static void main(String..args)
  • 12. So What is Micronaut? Really? • An Application Framework for the Future • Reflection Free, Runtime Proxy Free, No Dynamic Classloading (in 1.1) • Ahead of Time (AOT) Compilation AOT APIs • ... oh and let's you build Microservices
  • 13. Micronaut and GraalVM • A New Universal Virtual Machine from Oracle • Features a native-image Tool • Converts Java -> native machine code using AOT • Works well with Micronaut • Startup time 20ms and Memory Consumption 18MB! http://www.graalvm.org
  • 14. Micronaut's Solutions Problem Solution Limited Annotation API Precomputed AnnotationMetadata Type Erasure Precomputed Argument Interface Slow Reflection Eliminate Reflection Reflective Data Caches Zero Data Caches Classpath Scanning No Classpath Scanning Slow Dynamic Class Loading No Dynamic Class Loaders
  • 16. @Introspected @Introspected class MyBean { private List<String> names; //getter/setter omitted } • AOT Reflection-free replacement for java.beans.Introspector • Set/get bean properties, create instances • Includes AnnotationMetadata
  • 17. AnnotationMetadata AnnotationMetadata metadata = BeanIntrospection.getIntrospection(MyBean.class) .getAnnotationMetadata(); if (metadata.hasStereotype(SomeAnnotation.class)) { // do stuff } • AOT Computed / Merged Annotation Replacement for Reflection based API • Includes knowledge of meta-
  • 18. AnnotationMetadata Why? • All the Nullable annotations!!! • javax.annotation.Nullable (Java) • org.jetbrains.annotations. Nullable (Kotlin) • edu.umd.cs.findbugs. annotations.Nullable (Spotbugs) • org.springframework. lang.Nullable (Spring)
  • 19. Argument BeanProperty<MyBean, List> property = introspection.getRequireProperty("names", List.class); // returns an Argument with an underlying type of String Optional<Argument> typeVariable = property.asArgument() .getFirstTypeVariable() • AOT Computed Generic Type information • No type erasure / crazly reflection logic to get the type argument
  • 20. Argument Why? • You think resolving generic types in simple? https://github.com/spring-projects/ spring-framework/blob/master/spring- core/src/main/java/org/ springframework/core/ ResolvableType.java
  • 22. BeanDefinition ApplicationContext ctx = ApplicationContext.run(); BeanDefinition<MyBean> definition = ctx.getBeanDefinition(MyBean.class); • Contains precomputed AnnotationMetadata and generic type info • Used by ApplicationContext to instantiate beans
  • 23. BeanDefinition • Bean definitions produced for any @Singleton • Constructor injection used by default • Use @Factory for beans you cannot annotate • Compliant with javax.inject spec and TCK
  • 24. @ConfigurationProperties Type Safe Configuration @ConfigurationProperties("example") class ExampleConfiguration { // getters/setters omitted private String name; } ApplicationContext context = ApplicationContext.run("example.name":"Demo"); FooConfiguration config = context.getBean(FooConfiguration); assert config.name == 'Demo'
  • 25. @Requires Conditional Beans Made Easy @Requires(property="example.enabled") @Requires(beans=DataSource.class) @Requires(missingBeans=Example.class) @Singleton class DefaultExampleBean implements Example { ... } ApplicationContext context = ApplicationContext.run("example.enabled":"true") Example example = context.getBean(Example)
  • 26. @Executable @Scheduled(fixedRate = "5m") // @Scheduled annotated with @Executable void everyFiveMinutes() { messageService.sendMessage("Hello World"); } • Common Stereotype annotation • Identifies where framework invokes your code • Produces reflection-free ExectubleMethod instance
  • 27. @ExecutableMethodProcessor public class ScheduledMethodProcessor implements ExecutableMethodProcessor<Scheduled> { public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) { // do stuff with the bean } } • Processes only methods annotated by type argument • In the above case setting up a scheduled job
  • 29. @Around @Retryable // @Retryable is annotated with @Around void invokeMe() { // do stuff } • Intercepts a method with a MethodInterceptor • No runtime proxies (compile time proxies) or reflection needed • No FancyProxyFactoryBean or containers needed!
  • 30. @Around @Around @Type(DefaultRetryInterceptor.class) public @interface Retryable { // annotation attributes } • Use @Type to specify the implementation • At compilation Micronaut applies the AOP advise
  • 32. Micronaut Startup and Memory Runtime Memory Startup JDK 11 75MB 1.1s JDK 13 75MB 900ms JDK 13 + CDS 75MB 400ms GraalVM Substrate 15MB 21ms
  • 33. Summary • Micronaut Provides an Awesome Set of Framework Primitives • Sacrifices Compilation Speed to Gain so Much More • Solves Problems with Spring, Jakarta EE and Java in General • Opens the Door to GraalVM Native • Come learn more in my "Micronaut Deep Dive" talk at 6PM!
  • 34. Q & A