82
1 What is New on the Java Platform? Jinyoung Kang Java Architect & Consultant Sun Microsystems, KOREA

4 자바플랫폼의 신기능-강진영

Embed Size (px)

Citation preview

Page 1: 4 자바플랫폼의 신기능-강진영

1

What is New on the Java Platform?Jinyoung KangJava Architect & ConsultantSun Microsystems, KOREA

Page 2: 4 자바플랫폼의 신기능-강진영

2

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 3: 4 자바플랫폼의 신기능-강진영

3

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java ● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 4: 4 자바플랫폼의 신기능-강진영

4

Java Platform Roadmap at a Glance

2006 2007 2008 2009

Open Sourcing Java'It’s not a matter of when but how'

OpenJDK™ Launch

Java SE 6 Java SE 7

JavaFX SDKAnnounceJavaFX

JRE 6u10'Consumer JRE'

JRE 6u5p'Performance JRE'

ModularityMultiple Languages

Rich Clients

Page 5: 4 자바플랫폼의 신기능-강진영

5

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java ● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 6: 4 자바플랫폼의 신기능-강진영

6

Annotations Today• Annotations on declarations only

> Classes

> Methods

> Fields

> Locals

• Proposal: Allow annotations on type uses

@Deprecated class Signer { ...

@Override boolean equals(...

@Id String customerId;

@SuppressWarnings(“unchecked”) List<String> = new ArrayList();

Page 7: 4 자바플랫폼의 신기능-강진영

7

JSR 308 – Annotations on Java TypesTwo problems with annotations in Java 1.5:1. Syntactic limitation on annotations• Can only be written on declarations2. Semantic limitation of the type system• Doesn't prevent enough bugs

JSR 308 addresses these problems:• Extends Java programming language syntax to permitannotations in more locations• Enables creation of more powerful annotation processors

Page 8: 4 자바플랫폼의 신기능-강진영

8

Syntactic problem: Annotations on declarations only* Classes

package java.security;@Deprecated class Signer { ... }

* Methods@Test void additionWorks() { assert 1 + 1 == 2; }@Override boolean equals(MyClass other) // warning

* Fields@CommandLineArg(name="input", required=true)private String inputFilename;

* Locals/statementsList<Object> objs = ...;@SuppressWarnings List<String> strings = objs;

* Goal: Write annotations on type uses

Page 9: 4 자바플랫폼의 신기능-강진영

9

Semantic problem: Weak type checking• Type checking prevents many bugs

> int i = “JSR 308”;• Type checking doesn't prevent enough bugs

> getValue().toString(); // NullPointerException• Cannot express important properties about code

> Non-null, interned, immutable, encrypted, tainted, ...• Solution: pluggable type systems

> Design a type system to solve a specific problem> Annotate your code with type qualifiers> Type checker warns about violations (bugs)> Using annotations insulates the language in case we make a

• mistake designing the type system

Page 10: 4 자바플랫폼의 신기능-강진영

10

JSR 308 – Annotations on Java Types• Type checking prevents many bugs, but does

not prevent enough bugs

• Cannot express important properties about code> Non-null, interned, immutable, encrypted, ...

getValue().toString() //Potential NPE

Page 11: 4 자바플랫폼의 신기능-강진영

11

Example of JSR 308* GenericsList<@NonNull String> stringList; * Local variables@NonEmpty List<String> stringList;* castsGraph g = new Graph();... //add nodes and edges//Now g2 will not be change any more@Immutable Graph g2 = (@Immutable Graph)g;* receiver/** myMarshaller.marshal(myJaxb, myWriter)* does not modify myMarshaller */void marshall(@Readonly Object jaxbElement , @Mutable Writer writer) @Readonly

Page 12: 4 자바플랫폼의 신기능-강진영

12

JSR 308: How to get involved• Web search for "JSR 308" or "Annotations on Java types"• Completely open mailing list• Specification document• Reference implementation (patch to OpenJDK compiler)• Checkers Framework

> 5 checkers built so far> @NonNull @Interned @Readonly @Immutable> Basic checker (for any annotation name)

• Go forth and prevent bugs!

Page 13: 4 자바플랫폼의 신기능-강진영

13

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java (JSR )● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 14: 4 자바플랫폼의 신기능-강진영

14

Goals of the Java Module System

Development Deployment

More classes to deploy

More classes to reuse

Access control

Packages

Interfaces

Assertions

Classloaders

Versioning

Dependency control

Distribution format

Modules

Page 15: 4 자바플랫폼의 신기능-강진영

15

Goals of the Java Module System

Development goals for the Java Module System

Access control

Packages

Interfaces

Assertions

Promote modular programmingFirst-class module concept in language & VMReflective module metadata

Support JDK™ software modularizationPlatform ProfilesEndorsed Standards Override Mechanism

Page 16: 4 자바플랫폼의 신기능-강진영

16

Goals of the Java Module System

Deployment goals for the Java Module System

Classloaders

Versioning

Dependency control

Distribution format

Address "JAR hell"Better distribution format than JAR filesEnable side-by-side versioningSimple and predictable runtime model

Support entire spectrum of Java programsRepository infrastructure to isolate modulesCustomizable for different environments(e.g. applets) and module systems

Page 17: 4 자바플랫폼의 신기능-강진영

17

JSR 277 “Java Module System”• JSR 294 owned development modules

("superpackages")• All modularity discussions now happen in JSR

277> Development modules in the Java language> Deployment module framework> Default deployment module system: The JAM Module

System

Page 18: 4 자바플랫폼의 신기능-강진영

18

Modularity In Java Today• Packages

> Package names are hierarchical> Package memberships are not

• Access control> public, protected, private, default> No real control on packages – com.sun packages> Rely on documentations and comments to describe

official APIs• Interfaces

> Not always desirable to have all members public

Page 19: 4 자바플랫폼의 신기능-강진영

19

A Typical Package hierarchyorg/ netbeans/ core/ Debugger.class ... utils/ ErrorTracker.class ... wizards/ JavaFXApp.class ... addins/ ...

Page 20: 4 자바플랫폼의 신기능-강진영

20

org.netbeans.core – obvious “unit”org/ netbeans/ core/ Debugger.class ... utils/ ErrorTracker.class ... wizards/ JavaFXApp.class ... addins/ ...

Page 21: 4 자바플랫폼의 신기능-강진영

21

org/ netbeans/ core/ Debugger.class ... utils/ ErrorTracker.class ... wizards/ JavaFXApp.class ... addins/ ...

org.netbeans.core – conceptual “module”

Page 22: 4 자바플랫폼의 신기능-강진영

22

Modules in the Java Language// org/netbeans/core/Debugger.javamodule org.netbeans.core;package org.netbeans.core;public class Debugger { ... new ErrorTracker() ...}// org/netbeans/core/utils/ErrorTracker.javamodule org.netbeans.core;package org.netbeans.core.utils;module class ErrorTracker { module int getErrorLine() { ... }}// org/netbeans.core/module-info.java@Version("7.0")@ImportModule(name="java.se.core",version="1.7+")module org.netbeans.core;

Module concept in the language

Module access specified in the

language

One module has many packages

Module dependencies

specified in thelanguage

Page 23: 4 자바플랫폼의 신기능-강진영

23

Compiling and running a Java module> javac org/netbeans/core/*> javac org/netbeans/core/utils/*

> java org.netbeans.core.Debugger

Page 24: 4 자바플랫폼의 신기능-강진영

24

Impact of modules in the language & VM• module restricted keyword• module-info.java for module-level annotations• package-info.java can declare module membership• Classfile attribute for module membership• Classfile flag for "module-private" accessibility• Module-private accessibility enforced by the Java Virtual

Machine• javadoc and javap understand modules in .java and

.class files

Page 25: 4 자바플랫폼의 신기능-강진영

25

Deployment goals for the Java Module System

Classloaders

Versioning

Dependency control

Distribution format

Address "JAR hell"Better distribution format than JAR filesEnable side-by-side versioningSimple and predictable runtime model

Support entire spectrum of Java programsRepository infrastructure to isolate modulesCustomizable for different environments(e.g. applets) and module systems

Page 26: 4 자바플랫폼의 신기능-강진영

26

The JAM Module System• JAva Modules• A standard file format and predictable runtime model across Java• SE 7 implementations

> JAR-like file format> Easy, reflective, extensible metadata> Deterministic module resolution algorithm to address JAR hell> Deterministic module initialization algorithm> Integrated in platform, tools, class libraries ...

• JAM modules are simple to read and write> Addresses 80% of the problem space, not 95%> You can make a system better by keeping things out> Once a feature is added, it can never be removed> If a feature is left out, it can always be added later

Page 27: 4 자바플랫폼의 신기능-강진영

27

JAM metadata// org/netbeans/core/module-info.java@Version("7.0")@MainClass("org.netbeans.core.Main")@Attribute(name="IDE", value="NetBeans")

@ImportModules { @ImportModule(name="java.se.core", version="1.7+"),

@ImportModule(name="org.foo.util", version="1.0", reexport=true)}@ImportPolicyClass("org.netbeans.CustomPolicy")@ModuleInitializerClass("org.netbeans.core.Init")

@PlatformBinding(os="solaris", arch="sparc")@ExportResources({"icons/**"})module org.netbeans.core;

Version

Initializer

Module dependencies

Attributes

Main class

Custom importpolicy

Platform specific

Exported resources

Page 28: 4 자바플랫폼의 신기능-강진영

28

Compiling and running a JAM module• javac org/netbeans/core/*• javac org/netbeans/core/utils/*

• jam cvf org.netbeans.core-7.0.jam

org/netbeans/core/* org/netbeans/core/utils/*

• java -jam org.netbeans.core-7.0.jam

• cp org.netbeans.core-7.0.jam /netbeans/repository• java -module org.netbeans.core:6.0+

-repository /netbeans/repository

Page 29: 4 자바플랫폼의 신기능-강진영

29

org.netbeans.core-7.0.jam• /META-INF/MANIFEST.MF• /MODULE-INF/MODULE.METADATA• /MODULE-INF/bin/xml-windows.dll• /MODULE-INF/bin/xml-linux.so• /MODULE-INF/lib/xml-parser.jar• /org/netbeans/core/module-info.class• /org/netbeans/core/Main.class• /org/netbeans/core/Debugger.class• /org/netbeans/core/utils/ErrorTracker.class• /icons/graphics.jpg•

• .jam.pack.gz extension for Pack200-gzipped JAM module

Module metadata

Native libraries

JAR files

Other resources

Page 30: 4 자바플랫폼의 신기능-강진영

30

No more JAR hell• A JAM module definition imports other JAM module definitions by name• Module resolution finds module definitions to satisfy imports predictably• Different versions of the "same" module definition (B) can co-exist• If different versions of a module definition satisfy an import, use the

highest• A single version of a module definition (E) can be shared between

modules

Page 31: 4 자바플랫폼의 신기능-강진영

31

After a JAM module definition is resolved...• A JAM module instance is created and initialized• A JAM module instance has its own classloader• If JAM module definition A imports JAM module definition B, then A's• classloader delegates to B's classloader for classes exported by B• Classloading is completely deterministic

Page 32: 4 자바플랫폼의 신기능-강진영

32

Deployment goals for the Java Module System

Classloaders

Versioning

Dependency control

Distribution format

Address "JAR hell"Better distribution format than JAR filesEnable side-by-side versioningSimple and predictable runtime model

Support entire spectrum of Java programsRepository infrastructure to isolate modulesCustomizable for different environments(e.g. applets) and module systems

Page 33: 4 자바플랫폼의 신기능-강진영

33

Module Repositories

Bootstrap repositoryStandard modules

from JDK

Extension modules

Shared modules per system

Shared modules per user

Application-specific modules

Extension repository

Bootstrap repository

Global repository

User repository

Application repository

• A hierarchy of repositories

Page 34: 4 자바플랫폼의 신기능-강진영

34

OSGi in the Java Module System• Recap:

> The Java Module System is a framework> Defines key abstractions which concrete module systems can support> Allows different concrete module systems to co-exist and compete> Invents fundamental concepts missing in existing module systems> Repository is the key abstraction

• An OSGi container could implement the Repository API• A JAM module in JDK7 will be able to import an OSGi bundle

Page 35: 4 자바플랫폼의 신기능-강진영

35

OSGi can implement the deployment framework

Page 36: 4 자바플랫폼의 신기능-강진영

36

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java ● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 37: 4 자바플랫폼의 신기능-강진영

37

What is a Closure?• A closure is a function that refers to free

variables in its lexical context• A function is a block of code with parameters

> May optionally produce a result• free variables are identifiers used, but not

defined by the closure

Definition from Neal Gafter's 2007 JavaOne presentation

Page 38: 4 자바플랫폼의 신기능-강진영

38

Why Closures?• Allows blocks of code to be treated as data and

reused> Captures the environment> Provides a function pointer type of concept

• Reduces the amount of code that you write> Hides boiler plate code

• Allows you to write methods that behave and look like control statements in the language

Page 39: 4 자바플랫폼의 신기능-강진영

39

Closure Expressions• With one and two argument

• Does not return any values (void):

• With local variables

double log = { double x => Math.log(x) }.invoke(10);int sum = { int x, int y => x + y }.invoke(3, 4); //will return 7

{ char c => System.out.println(c); }.invoke('@'); //will print @

*Examples from http://tronicek.blogspot.com/2007/12/closures-closure-is-form-of-anonymous_28.html

{ int n => int m = n + 1; System.out.println(m * m);

}.invoke(3); //will print 16

Page 40: 4 자바플랫폼의 신기능-강진영

40

Function Types• Defining a closure as a datatype• { formal parameters => return type }• Examples of function types

• Function with one argument and returns a String

{ int, String => void }{ => void }

{int => String} toBinary = { int x =>Integer.toBinaryString(x)};

System.out.println(toBinary.invoke(11));//will return 1011

*Examples from http://tronicek.blogspot.com/2007/12/function-types.html

Page 41: 4 자바플랫폼의 신기능-강진영

41

Access to Local Variablesstatic void doTwice({ => void } block) { block.invoke(); // will print 10 int x = 20; block.invoke(); // will print 11 System.out.println(x); // will print 20 } public static void main(String[] args) {

@Shared int x = 10; // the block is "packed" with variable x doTwice({ => System.out.println(x++); }); }

*Adapted from http://tronicek.blogspot.com/2008/01/completion-transparency.html

Page 42: 4 자바플랫폼의 신기능-강진영

42

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java ● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 43: 4 자바플랫폼의 신기능-강진영

43

Multi-Catch*

• A longstanding request to allow catching X1 and X2 together, without resorting to catching Exception itself

• A disjunctive type X1, X2 represents X1 or X2> The members of e are those of a common superclass

try { ... } catch (X1 e) { foo(); }} catch (X2 e) { foo(); }} catch (X3 e) { bar(); }

try { ... } catch (X1, X2 e) { foo(); }} catch (X3 e) { bar(); }

Page 44: 4 자바플랫폼의 신기능-강진영

44

Safe re-throwvoid m() throws X1,X2 {

try { /* Something that can throw X1,X2 */ }catch (Throwable e) {

logger.log(e);throw e; // Error: Unreported exception Throwable

}}* We want to express we're rethrowing the exception in the try{}

void m() throws X1,X2 {try { /* Something that can throw X1,X2 */ }catch (final Throwable e) {

logger.log(e);throw e; // Compiles OK; can throw X1,X2

}}

Page 45: 4 자바플랫폼의 신기능-강진영

45

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java ● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 46: 4 자바플랫폼의 신기능-강진영

46

AWT Enhancements• Supports translucent

and shaped windows• Leverages hardware

acceleration (OpenGL / Direct3D) where available

http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/

Page 47: 4 자바플랫폼의 신기능-강진영

47

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java ● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 48: 4 자바플랫폼의 신기능-강진영

48

Developing Swing Applications Today

public class MySwingApp {//Good luck

}

Page 49: 4 자바플랫폼의 신기능-강진영

49

Swing Application Framework Architecture

LifecycleResourcesActionsTasksSession state

Page 50: 4 자바플랫폼의 신기능-강진영

50

Swing Application FrameworkApplication Controller

Application Framework

Web Service

Database

Data Synchronization

Data Conversion

Data Validation

Data ModelResourcesActions

Lifecycle Tasks

Page 51: 4 자바플랫폼의 신기능-강진영

51

Framework Components• Swing Application

Framework – JSR296 > Lifecycle methods> Resource injections> Maintain application

states> Tasks

• Beans Binding – JSR295> Connecting JavaBeans'

properties> Keeping them in sync

Resources Actions

LifecycleTasks

Data Synchronization

Data Conversion

Data Validation

http://appframework.dev.java.nethttp://beansbinding.dev.java.net

Page 52: 4 자바플랫폼의 신기능-강진영

52

Using the Framework (JSR 296)• Create a subclass of Application• Create and show your GUI in the startup method• Use ApplicationContext services to

> define/manage actions and tasks> load/inject resources> save/restore session state

• Call Application.launch from your main method

Page 53: 4 자바플랫폼의 신기능-강진영

53

Swing Application Framework Example – 1public class MyApp extends SingleFrameApplication {

@Override protected void startup() {JLabel label = new JLabel("Hello World");show(label);

}public static void main(String[] args) {

Application.launch(MyApp.class, args);}

}// SingleFrameApplication is a subclass of Application

Page 54: 4 자바플랫폼의 신기능-강진영

54

Application Lifecycle Methods

Calls initialize(), startup(), ready() on EDT thread.

Performs initializations that must happen before the GUI is created like setting look & feel.

Creates the initial GUI and shows it. All applications will override this method.

Any work that must wait until the GUI is visible and ready for input.

Calls shutdown() if the exitListeners do not veto. Main frame's Windowlistener calls exit().

Take the GUI down and do final cleanup.

Page 55: 4 자바플랫폼의 신기능-강진영

55

Application Resources• Defined with ResourceBundles• Organized in resources subpackges• Used to initialize properties specific to:

> locale> platform> a few related values…

Page 56: 4 자바플랫폼의 신기능-강진영

56

ResourcesMaps• Encapsulate list of ResourceBundles whose

names arebased on a class• Automatically parent-chained

> Superclass resources> Application-wide resources

• Support extensible string to type resource conversion

• Support ${resource key} substitution: version = 1.0 title = My Application version ${version}

Page 57: 4 자바플랫폼의 신기능-강진영

57

Using ResourceMaps: ExampleApplicationContext c = Application.getInstance().getContext()ResourceMap r = c.getResourceMap(MyForm.class);

r.getString("aFormat", "World") => "Hello World"r.getColor("colorRBGA") => new Color(5, 6, 7, 8)r.getFont("aFont") => new Font("Arial", Font.PLAIN, 12)

# resources/MyForm.propertiesaString = Just a stringaFormat = Hello %sanInteger = 123aBoolean = TrueanIcon = myIcon.pngaFont = Arial-PLAIN-12colorRGBA = 5, 6, 7, 8color0xRGB = #556677

Page 58: 4 자바플랫폼의 신기능-강진영

58

Actions: A (very) brief reviewEncapsulation of an ActionListener and:• some purely visual properties• enabled and selected boolean properties

// define sayHello Action – pops up message DialogAction sayHello = new AbstractAction("Hello") {

public void actionPerformed(ActionEvent e) {String s = textField.getText();

JOptionPane.showMessageDialog(s);}

};// use sayHello – set the action propertytextField.setAction(sayHello);button.setAction(sayHello);

Page 59: 4 자바플랫폼의 신기능-강진영

59

Actions: What We Like• Encapsulation of default GUI + behavior• The enabled and selected properties• Reusability

Page 60: 4 자바플랫폼의 신기능-강진영

60

The new @Action annotation

• ActionEvent argument is optional• Used to define a “sayHello” ActionMap entry• Encapsulation of default GUI + behavior

// define sayHello Action – pops up message Dialog@Action public void sayHello() {String s = textField.getText();JOptionPane.showMessageDialog(s);}// use sayHello – set the action propertyAction sayHello = getAction("sayHello");textField.setAction(sayHello);button.setAction(sayHello);

Page 61: 4 자바플랫폼의 신기능-강진영

61

Tasks• Inherit the SwingWorker API• Support for monitoring• Title, Start/Done, etc.• Asynchronous @Actions return Tasks• Easy to handle non-blocking actions

Page 62: 4 자바플랫폼의 신기능-강진영

62

Asynchronous @Action example@Action public Task sayHello() { // Say hello repeatedly

return new SayHelloTask();}private class SayHelloTask extends Task<Void, Void> {

@Override protected Void doInBackground() {for(int i = 0; i <= 10; i++) {

progress(i, 0, 10); // calls setProgress()message("hello", i); // resource defines formatThread.sleep(150L);

}return null;}@Override protected void succeeded(Void result) {

message("done");}@Override protected void cancelled() {

message("cancelled");}

}

Page 63: 4 자바플랫폼의 신기능-강진영

63

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java ● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 64: 4 자바플랫폼의 신기능-강진영

64

Beans Binding (JSR 295)• Keeps properties of two objects in sync• Source properties can specified using

Expression Language:• ex: “${customer}” or “${employee.salary}”• Does not require special object types:• Bindings.createAutoBinding(READ_WRITE,sour

ce,source Prop, target, target Prop);

Page 65: 4 자바플랫폼의 신기능-강진영

65

Beans Binding Feature• Different update strategies• Read once, read only from source, keep source

and target in sync• Ability to do validation• Ability to transform value• String to Color, Date to String

Page 66: 4 자바플랫폼의 신기능-강진영

66

Beans Binding Example – Before 295 faceSlider.addChangeListener(new ChangeListener() {

public void stateChanged(ChangeEvent e) {caricature.setFaceStyle(faceSlider.getValue());

}});caricature.addPropertyChangeListener(new PropertyChangeListener() {

public void propertyChange(PropertyChangeEvent e) {if (e.getPropertyName() == “faceStyle”) {faceSlider.setValue(caricature.getFaceStyle());

}} });

http://weblogs.java.net/blog/shan_man/archive/2007/09/beans_binding_1.html

Page 67: 4 자바플랫폼의 신기능-강진영

67

Beans Binding Example – JSR 295Property faceStyleP= ELProperty.create(“${faceStyle}”);Property sliderP = BeanProperty.create(“value”);Binding binding = Bindings.createAutoBinding(

UpdateStrategy.READ_WRITE, caricature, faceStyleP, // source faceSlider, sliderP); // target

binding.bind();

http://weblogs.java.net/blog/shan_man/archive/2007/09/beans_binding_1.html

Page 68: 4 자바플랫폼의 신기능-강진영

68

DEMO

Page 69: 4 자바플랫폼의 신기능-강진영

69

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java ● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 70: 4 자바플랫폼의 신기능-강진영

70

File System API• What's wrong with java.io.File?

> No concept of file systems, attributes, 'link', storages, ...

• Proposed new API (main classes only)> FileSystem – factory for objects to access file and

other objects in file system> FileRef – reference to a file or directory, contains

methods to operate on then> Path – a FileRef that locates a file by a system

dependent path> FileStore – underlying storage pool, device,

partition, etc• http://openjdk.java.net/projects/nio

Page 71: 4 자바플랫폼의 신기능-강진영

71

File System API Example – 1 Path home = Path.get(“/home/obiwan”);//Reference to .bash_profile in /home/obiwanPath profile = home.resolve(“.bash_profile”);

profile.copyTo(home.resolve(“.bash_profile.backup”));

WritableByteChannel chan = profile.newSeekableByteChannel(APPEND);

// Append stuff to .bash_profile...

chan.close();

Page 72: 4 자바플랫폼의 신기능-강진영

72

Agenda

● Java Platform Roadmap of a Glance ● Annotations on Java Types (JSR 308)● Goals of the Java Module System (JSR 277, 294)● Closure of Java ● Some language features under consideration ● AWT Enhancements ● Swing Application Framework (JSR 296)● Bean Binding (JSR 295) ● File System API (JSR 203)● ForkJoin Framework (JSR 166y)● Summary

Page 73: 4 자바플랫폼의 신기능-강진영

73

Hardware trends• As of ~2003, we stopped seeing increases in CPU clock rate

• Moore’s law has not been repealed!> Giving us more cores per chip

rather than faster cores● Maybe even slower cores

• Chart at right shows clock speed of Intel CPU releases over time> Exponential increase until 2003> No increase since 2003

• Result: many more programmers become concurrent programmers (maybe reluctantly)

Page 74: 4 자바플랫폼의 신기능-강진영

74

JSR 166y: ForkJoin • “The free lunch is over”

> No more relying on faster CPUs to compensate for poor coding

• Multicore CPUs> Performance improvement only possible by exploiting

these• Concurrency and parallelism techniques are no

longer confined to HPC realm• java.util.concurrent.forkjoin package• Processor hints

> Runtime.availableProcessors()

Page 75: 4 자바플랫폼의 신기능-강진영

75

Parallelization technique: divide-and-conquer• Divide-and-conquer breaks down a problem into subproblems,

• solves the subproblems, and combines the result

• Example: merge sort> Divide the data set into pieces

> Sort the pieces

> Merge the results

> Result is still O(n log n), but subproblems can be solved in parallel> Parallelizes fairly efficiently – subproblems operate on disjoint data

• Divide-and-conquer applies this process recursively> Until subproblems are so small that sequential solution is faster

> Scales well – can keep many CPUs busy

Page 76: 4 자바플랫폼의 신기능-강진영

76

Fork-join parallelism• The key to implementing divide-and-conquer is the invoke-in-parallel

operation> Create two or more new tasks (fork)> Suspend the current task until the new tasks complete (join)

• Naïve implementation creates a new thread for each task> Invoke Thread() constructor for the fork operation> Thread.join() for the join operation> Don’t actually want to do it this way

● Thread creation is expensive● Requires O(log n) idle threads

• Of course, non-naïve implementations are possible> Package java.util.concurrent.forkjoin proposed for JDK 7 release

offers one> For now, download package jsr166y from> http://gee.cs.oswego.edu/dl/concurrency-interest/index.html

Page 77: 4 자바플랫폼의 신기능-강진영

77

Solving select-max with fork-joinThe RecursiveAction class in the fork-join framework is idealfor representing divide-and-conqure solutions

class MaxSolver extends RecursiveAction { private final MaxProblem problem ;

int result; protected void compute() {

if (problem.size < THRESHOLD) result = problem.solveSequentially();

else {int m = problem.size / 2; MaxSolver left, right;left = new MaxSolver(problem.subproblem(0, m)); right = new MaxSolver(problem.subproblem(m, problem.size));forkJoin(left, right); result = Math.max(left.result, right.result); }

} }

ForkJoinExecutor pool = new ForkJoinPool(nThreads); MaxSolver solver = new MaxSolver(problem); pool.invoke(solver);

Page 78: 4 자바플랫폼의 신기능-강진영

78

Work stealing• Fork-join framework is implemented using work-stealing

> Create a limited number of worker threads> Each worker thread maintains a private double-ended work

queue (deque)● Optimized implementation, not the standard JUC deques

> When forking, worker pushes new task at the head of its deque> When waiting or idle, worker pops a task off the head of its

deque and executes it● Instead of sleeping

> If worker’s deque is empty, steals an element off the tail of the deque of another randomly chosen worker

Page 79: 4 자바플랫폼의 신기능-강진영

79

Summary• Lots of new things coming• Will make Java applications smaller, more

concise, easier to read (and understand), less errors

• Lots of nice libraries that are going to exploit the hardware

• Platform will be more robust and scalable

Page 80: 4 자바플랫폼의 신기능-강진영

80

Summary Proposed JSRs for Java SE 7 Platform• JSR 277: Java Module System• JSR 294: Improved modularity support in the Java programming language

• JSR 295: Beans binding

• JSR 303: Bean validation

• JSR 292: Supporting Dynamically Typed Languages

• JSR 296: Swing application framework

• JSR 203: More new I/ O APIs for the Java Platform (NIO.2)

• JSR 220: Enterprise JavaBeans™ 3.0

• JSR 255: JMX specification, version 2.0

• JSR 262: Web services connector for JMX agents

• JSR 260: Javadoc™ Tag Technology Update• JSR(s) TBD Java Language changes

• JSR 308: Annotations on Java Types

• JSR 310: Date and Time API

Page 81: 4 자바플랫폼의 신기능-강진영

81

Thank You :-)Jinyoung [email protected]://planetnetbeans.org/ko/index.html

Page 82: 4 자바플랫폼의 신기능-강진영

82

Jinyoung [email protected]://planetnetbeans.org/ko/index.html

:-)