Java One - PowerPoint PPT Presentation

1 / 100
About This Presentation
Title:

Java One

Description:

CMT by default, BMT by annotation. Transaction attribute required by default ... View it at http://java.sun.com/javaone/ Collections in JDK 5 ... – PowerPoint PPT presentation

Number of Views:120
Avg rating:3.0/5.0
Slides: 101
Provided by: ebenh
Category:
Tags: java | one

less

Transcript and Presenter's Notes

Title: Java One


1
Java One
  • Technical Conference Report
  • 2005

2
Goals
  • Communicate an overview of the technical content
    at Java One.
  • Articulate and generate ideas for the enterprise
    platform.

3
General Presentation Overview
  • General Sessions/Keynote overview
  • Java SE 6
  • Java EE 5
  • EJB 3.0
  • Concurrency
  • Maven
  • APT
  • Agile Methods

4
Web-Specific Presentation Overview
  • Attend in Michigan July 25
  • Rich UIs with AJAX and JSF
  • What's New in WebLogic 9
  • Hacking a Web Application
  • Hibernate 3
  • JavaServer Faces and Shale
  • Tapestry
  • Scripting Framework
  • Other talk overviews

5
General Presentation
6
General Session and Announcements
  • Start of Participation Age
  • Enterprise Service Bus JBI implementation open
    source
  • get it from open-esb.java.net
  • Studio Creator EA 2
  • Built on NetBeans
  • WYSIWYG JSR 168 Portlets, calendars, sortable
    tables, WS

7
Platform Roadmap
  • Mustang is Java SE 6, Dolphin Java SE 7
  • See Mustang spec JSR 270
  • Summer 2006 for Mustang release.
  • Major new edition every 18 months

8
Themes for Java SE 6
  • 1) Compatability, Stability, Quality
  • 2) Diagnosis, Monitor, Manage
  • JMX upgrade, jconsole upgrade, jvm
    instrumentation
  • 3) XML and Web Services
  • JAXWS 2, JAXB 2
  • End of the pure client

9
More Themes for Java SE 6
  • 4) Ease of Development
  • Simplify tasks (annotations and scripting
    languages)
  • JDBC 4.0 support, including DB XML
  • Javadoc update JSR 260 (big classes)
  • 5) Desktop Focus
  • Full Longhorn support with Avalon LNF
  • LCD Font rendering, system tray, boost for
    OpenGL/Direct X
  • 6) Compatability
  • Be more transparent http//mustang.dev.java.net.

10
JSE 6 Compiler API
  • JSR 199 Compiler API
  • Compiler c new Compiler()
  • c.setOutputDir(build/classes)
  • c.setSourceDir(src)
  • c.compile()
  • c.run(Main.class)

11
JSE 6 JDBC 4, JAXB 2.0, WS
  • Just tell driver to get a connection, less code.
  • java.sql.SQLXML support
  • Instead of dealing with XML at angle-bracket
    level
  • _at_XmlType public class SomeBean
  • //this bean now matches an XML document
  • _at_WebService public class Hello
  • //deployable after writing client factory code

12
JSE 6 Other improvements
  • Scriptable Dtrace
  • javac -cp jaxb/lib/ (dont have to specify
    each JAR)

13
Themes for Java SE 7 Dolphin
  • direct literal XML support
  • friends
  • new JVM bytecode for dynamic languages
  • More NIO (JSR 203)
  • Different package/deploy architecture (not JARs,
    EARs, etc)
  • BeanShell Scripting language support (JSR 274)

14
Platform Roadmap for EE
  • POJO based programming model.
  • Fewer deploy descriptors
  • Extensive annotations
  • Dependency injection
  • Annotations will map Java to XML, Java to DB, and
    simplify EJBs

15
Major Features for Java EE 5
  • WS support expanded
  • Support SOAP 1.2, Schema, WS-I (Basic profile,
    attachment profile)
  • Make WS easier (no clients, annotations). Ex
  • _at_WebService public class Hello
  • EJB 3, JSP 2.1 (mostly EL), JavaServer Faces
  • New Persistence API
  • One model usable in JSE/Entities

16
Status of Java EE 5
  • All Specs available now
  • Spec final draft Q305
  • Beta in Q405
  • Final Release Q106

17
Project Glassfish
  • an implementation of Java EE
  • Can be downloaded via CVS and built with Maven
  • See http//glashfish.dev.java.net

18
BEA Announcements
  • BEA will certify JavaServer Faces, Spring,
    Struts, and Beehive frameworks on their platform
  • WebLogic 9 will be out in August 05.
  • Workshop was retooled for Eclipse, and theyll
    make direct IDE support for Tomcat and Geronimo
    available in it.
  • Abstraction of their server tool allows admin of
    Tomcat and Geronimo from BEA console

19
EJB 3
  • No required Deployment Descriptor
  • No home object
  • No JNDI in client view
  • Business interface is now a POJO
  • Native O/R Mapping, simplified persistence
  • Compatibility with EJB 2.1 and 2.0 clients and
    beans

20
EJB 3 Stateless Session Bean and DataSource
Example
  • _at_Stateless public class PayrollBean implements
    IPayroll
  • _at_Resource DataSource empDB
  • public void doWork(int x)
  • Connection conn empDB.getConnection()
  • //do work with conn

21
Dependency Injection
  • _at_Resource works because of dependency injection
    at construction
  • Dynamic look up (no JNDI in developers view)

22
Simplified Client View
  • Session beans have only business interface
  • No RemoteExceptions are visible to client
  • 100 POJO interface
  • Access can be local or remote

23
EJB 3 Client View Example
  • _at_EJB ShoppingCart mycart
  • Collection cartItems myCart.getItems()

24
Transactions in EJB 3
  • CMT by default, BMT by annotation
  • Transaction attribute required by default
  • Transactions specified at class level, can be
    overridden at method level
  • Example
  • _at_TransactionAttribute(MANDATORY)
  • public void doWork(int I)

25
Security in EJB 3
  • Typically done at deploy time
  • Can override or specify at method level
  • Example
  • _at_RolesAllowed(HR-Admin)
  • public void doWork(Employee e)

26
Simplified Life Cycle Implementation
  • Container calls bean on life cycle events
  • _at_PostConstruct
  • _at_PreDestroy
  • _at_PrePassivate
  • _at_PostActivate
  • This removes ejbCreate, ejbRemove, etc.
  • Can attach callback listener class to respond to
    life cycle events.

27
Persistence in EJB 3
  • Goals include
  • Persistence API that includes use outside
    container
  • Support pluggable third party persistence at
    runtime
  • Support O/R (Hibernate, TopLink, JDO) based
  • Complete query capabilities
  • Support light-weight domain modeling, with
    inheritance and polymorphism

28
Entity Beans in EJB 3
  • Entities are now simple POJOs
  • No required interfaces
  • No required callback interfaces
  • Usable as regular objects in other tiers (can
    pass it around without needs for DTO)
  • Usable across multiple transactions, spanning
    multiple requests

29
Entity Manager
  • Like JDO Persistence Manager
  • Serves as factory for query objects
  • Developer controls mapping, which can be
    expressed in XML or annotations

30
Questions about EJB 3
31
App Server 9.0 and Java EE 5 SDK
  • Focus Ease of use (annotations)
  • Integration with many IDEs.
  • Self-managing and self-healing
  • Open source as Project Glassfish (Sun is
    responsible for compatability)

32
Writing Web Services in EE 5
  • _at_WebService on POJO (becomes wsdlport-type
    element)
  • _at_WebMethod on method (becomes wsdloperation
    element)
  • Non-annotated methods arent published to the
    service. Example
  • _at_WebService
  • public class Hello public String hi() return
    hello

33
Deploying Web Services in EE 5
  • Use apt to drop in autodeploy directory (code
    generation)
  • run method at http//localhost8090/HelloService?W
    SDL

34
Talks not Discussed Here
  • Designing a high-performance Call Detail Record
    application
  • Using JAAS to implement a BioMetric J2EE
    application authenticator
  • JavaServer Faces Ecosystem
  • MDBs and JCA
  • Pragmatic SOA (BPEL)
  • JMS Tips
  • NetBeans

35
Scott McNealy Keynote
  • Bridge the Digital Divide for healthcare and
    education
  • View it at http//java.sun.com/javaone/

36
Collections in JDK 5
  • Generics, covariants, concurrency should be
    discussed in their own presentations
  • Can read about concurrency in Mustang at
    http//gee.cs.oswego.edu/dl/concurrency-

37
Concurrency
38
Concurrency
  • New in Java 5 java.util.concurrent
  • Thread Pools, Task Scheduling
  • Concurrent Collections
  • Atomic variables
  • Locks, Conditions, Synchronizers

39
Why Concurrency?
  • wait(), notify(), and synchronize are hard to
    use, specified at a low level, can lead to poor
    performance
  • Lots of wheel reinventing

40
Goal of Concurrency
  • Do what Collections did for data structures
  • Allow development of thread-safe classes, such as
    servlets, built on concurrent building blocks
    (like ConcurrentHashMap)
  • Make some solved things easier for masses
  • Make very hard things solvable by experts

41
Task Scheduling (Executor)
  • Use anExecutor.execute(aRunnable)
  • Do NOT use new Thread(aRunnable).start()

42
Why Prefer Executor?
  • Executor framework allows for a variety of
    execution policies
  • Provides cancellation and shutdown support
  • Created via factory
  • Can customize shutdown hooks
  • Simpler interface
  • Code that submits a task doesnt have to know in
    what thread the task will run

43
Executor Service
  • ExecutorService supports graceful and immediate
    shutdown
  • Has a lifecycle
  • Has many useful utility methods
  • Can get a single threaded executor
  • Bad Example Webserver in a while() loop listens
    forever and starts a new thread for each request.

44
Threads
  • Threads are expensive to create, can require 500K
    of memory during creation
  • Your threads spend a lot of time
    context-switching, even if you have 10 processors
  • Whenever you want to start a thread, dont use
    Executor

45
Using Executor
  • Executor pool Executor.newFixedThreadPool(7)
  • socket.accept()
  • Runnable r new Runnable()
  • //handle request
  • pool.execute()

46
Interface Callable
  • Functional analog of Runnable
  • public interface CallableltVgt V call()

47
Future
  • Holds result of asynchronous call, normally a
    Callable. Can find out if this task is complete,
    cancelled, etc.
  • Implementing caches is tricky--often were just
    moving the bottleneck from computation to
    serialization most of the time.

48
ScheduledExecutorService
  • SES is a drop-in replacement for Timer
  • Supports pooling

49
Concurrent Collections
  • Pre Java 5 was thread-safe but not concurrent.
  • Every method was synchronized. This was okay
    because we werent on multi-core machines.
  • Azul has a 384-way box now--running Java on that
    would have been problematic.
  • Old collections required locking during iteration.

50
New ConcurrentHashMap
  • Drop-in replacement for Hashtable
  • No iterator throws ConcurrentModificationException
  • Allows read/write overlaps.
  • It is therefore weakly concurrent

51
New CopyOnWriteArrayList
  • Locking during iteration hurts scalability.
  • Changes made by other threads may or may not be
    noticed by reads

52
New Queue
  • retrofit (non-thread safe) implemented by
    LinkedList

53
New BlockingQueue
  • Extends Queue to provide two operations
  • take() wait for queue to be non-empty
  • put() wait for queue to have room

54
Use of monitor synchronization is fine for most
apps BUT
  • Single wait-set per lock
  • No way to interrupt a thread waiting for a lock
  • No way to time out when waiting for a lock
  • Locking must be block-structured
  • Inconvenient to acquire a variable number of
    locks at once.
  • Advanced techniques not possible
  • Lock objects address these concerns

55
Lock Objects
  • Address synchronization monitor issues
  • Provide a high-level interface
  • lock
  • tryLock (tells you if you got it)
  • unlock
  • newCondition (every object cant provide
    conditions)

56
ReentrantLock
  • High-Performance, covers 99 of use cases
  • Re-entrant, mutual exclusion lock offers same
    semantics as synchronized but with extra features
  • Can interrupt a thread waiting to acquire a lock
  • Can specify a timeout while waiting
  • Can poll for lock availability
  • Downside have to manually unlock (in finally )

57
Re-entrant Lock Example
  • Lock lock new ReentrantLock()
  • lock.lock()
  • try
  • //do work
  • catch
  • //resolve invariants and rethrow
  • finally
  • lock.unlock()

58
ReadWriteLock
  • Multiple reader, single writer exclusion lock
  • ReadWriteLock class defines a pair of locks
  • interface ReadWriteLock
  • Lock readLock()
  • Lock writeLock()
  • Use for frequent, long reads w/ few writes.
  • Various implementation policies

59
Condition Interface
  • Condition is an abstraction of wait/notify
  • Monitor-like operations for working with Locks
  • Can awaitUntil(Date deadline) or
  • awaitNanos(long nsToWait)
  • Advantages over wait/notify include multiple
    conditions per lock

60
Synchronizers
  • Utility classes
  • Low level

61
New Synchronizers
  • Semaphor Represents a permit manager
  • CountdownLatch Gate with one or more padlocks --
    allows 1 or more threads to wait for a set of
    threads to complete action
  • Exchanger Allows two threads to rendezvous and
    exchange data, then go their separate ways.

62
Atomic Variables
  • Support Compare-and-set
  • Get, set, and arithmetic operations
  • Abstraction of volatile variables
  • Ten main classes (AtomicInteger and other
    wrappers) can be used instead of synchronizing
    access

63
New Concurrency in Java 6
  • ConcurrentSkipLists
  • Deque interface for double-ended queues.

64
Maven
  • Goal to make development and project
    comprehension easier
  • Started in 2003, used by many Apache projects
  • Java focused now, but expanding
  • Provides library abstraction over subversion,
    ClearCase, etc.
  • It is a dependency-management and documentation
    tool. Applies patterns to a build infrastructure.

65
How Maven Achieves Goals
  • Declarative build
  • Use repositories for dependency management
  • plugins
  • documentation system
  • reporting system

66
Maven Advantages
  • Low setup cost
  • Easy to embrace best practices
  • Easy tool integration

67
Nomenclature
  • POM
  • Artifacts
  • SiteDoc
  • Reporting

68
POM
  • fundamental unit of work
  • A client.jar, app.jar and common.jar represent 3
    different POMs
  • Usually is a deployable unit
  • SuperPOM is implicit parent for defaults

69
Repository
  • Where artifacts are stored
  • ibiblio stores 8000 projects
  • Local is a cache on developer box
  • Remote is a source over HTTP, CVS/SVN, FTP

70
Maven 2.0
  • Feature complete, in Alpha 3 now
  • Final version in August
  • Complete rewrite

71
Adding Dependencies in Maven
  • Declaration will download it
  • Dependencies are transitive
  • POMs must be in repository
  • Can make dependency exclusions

72
Maven Snapshots
  • Represents the last build
  • Automatically adds version, ts, build
  • Updates daily, on demand, or at intervals

73
Project File
  • Unified project file is self-contained
  • No file-system references make it usable from
    repository
  • Allows Profiles (user ID, sourceforge login, etc)
  • Supports BeanShell for rapid prototyping

74
More Maven Info
  • Sun uses Maven for its projects now (Glassfish)
  • Maven Book ranked 3rd in book sales at JavaOne
  • Plugins for xDoclet, numerous other tools
  • Website at http//maven.apache.org

75
APT
76
APT
  • Annotation Processing Tool
  • Metadata you can associate with program elements
  • Doesnt change your byte code, but could
  • Annotations can be read from Source, Reflection,
    or ByteCode

77
Annotating Interface Example
  • public _at_interface JavaTalk public boolean
    isAlumni() default false

78
Annotatable Structures
  • Enums
  • Strings
  • Primitives
  • Class objects
  • 1-dimension arrays

79
Why Annotations?
  • Support declarative programming style
  • Reduce boilerplate by generation
  • Ease maintenance by expressiveness

80
Meta-Annotations
  • java.lang.annotation.
  • _at_Target kinds of elements Annot can be used on
  • _at_Retention sourceclassruntime
  • _at_Documented is in public API?
  • _at_Inherited can a subclass inherit this Annot.
    From its superclass?

81
Annotations Used In
  • JSR 181 (ES)
  • JSR 220 (EJB 3)
  • JSR 250 (Common Annotations)
  • testng.org (Junit extension)

82
APT is Meta-Programming
  • Annotations are an instance of programming based
    on programs structure
  • APT Annotation Processing Tool
  • Processes .java source files through apt to get
    XML, HTML, .java, etc.
  • Proceesing is recursive

83
How apt Works
  • Keeps track of all annotations and tries to
    discover something in classpath that knows how to
    deal with it.
  • Can then create additional documents for build or
    runtime
  • Because a new source could be created that also
    has annotations in it, apt must be recursive
  • Feed JAR and class files through apt, just like
    source.

84
APT API
85
Using Suns APT API
  • com.sun.mirror (not community standard)
  • Two parts
  • Language Modeling com.sun.mirror.declaration
  • Type System com.sun.mirror.type

86
Declarations in APT API
  • Declarations package represents structure of
    source code and its hierarchy
  • Declarations are program elements (Package, Enum,
    Field, Method, Constructor, AnnotationType, etc)
  • From a declaration you get
  • Doc comments
  • Source position
  • Names
  • Etc.

87
Type Hierarchy in APT API
  • Primitive, Void, Reference, Class, Enum,
    Interface, Array, etc.
  • From a Type you get
  • Type arguments
  • Corresponding declaration
  • Supertypes
  • Etc.

88
Processor - Tool Interaction
  • Annotations processor
  • Annotations processor factory
  • Annotations processor environment
  • Access to programming model
  • File creation
  • Diagnostics

89
Roles in Writing a Processor
  • Role 1 Writer of Annotations
  • Role 2 Writer of Annotation Processor
  • Role 2b Packager of Processor into JAR
  • Role 3 Client
  • Role 3b End user
  • Use API com.sun.mirror (not community standard)
  • Two parts
  • Language Modeling com.sun.mirror.declaration
  • Type System com.sun.mirror.type

90
Write Your Own Annotation Processor
91
Why Write Your Own Processor?
  • Add an operation to the type hierarchy
  • Let clients implement their own type-specific
    operations

92
Writing a Processor, pt1
  • Use Visitor pattern
  • Define Visitor interface with method for each
    type to be visited
  • visitFoo(Foo f)
  • visitBar(Bar b)
  • Include an accept() method with a visitor
    parameter in the type hierarchy
  • myClass.accept(myVisitor)
  • Client calls the accept() method

93
Writing a Processor, pt 2
  • public class MyFactory implements
    AnnotationProcessorFactory
  • public class MyProcessor implements
    AnnotationProcessor

94
Run the Processor
  • Install your annotation processor JAR on
    classpath
  • run apt
  • apt MySource.java

95
Future of APT
  • Will be reimplemented for Java 6
  • Existing APIs will be open-sourced
  • See JSR 199 Programmatic Access for Tools
  • Read http//java.sun.com/j2se/1.5.0/docs/guide/apt
    /index.html

96
Agile
97
Agile Methods
  • http//craiglarman.com
  • http//agilemodeling.com
  • http//davidhecksel.com
  • Agile Modeling
  • Enterprise Unified Process
  • Pragmatic Programmer
  • Death March
  • Balanced Agility and Discipline

98
Agile Ideas
  • Have a 10 minute stand up meeting every morning
  • Charge 1 if people are late to meeting
  • QA is constant throughout and is part of core
    team
  • Make your unit tests a release of their own.
  • If 3 weeks is too long, your task is too big

99
Presentation Available at
  • M\\somewhere

100
Discussion
Write a Comment
User Comments (0)
About PowerShow.com