SlideShare a Scribd company logo
1 of 149
Download to read offline
Java SE Beyond Basics:  Generics, Annotation, Concurrency, and JMX Sang Shin [email_address] www.javapassion.com Sun Microsystems Inc.
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hands-on Labs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generics
Sub-topics of Generics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generics: What is it? How do define it? How to use it?  Why use it?
What is Generics? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Definition of a Generic Class: LinkedList<E> ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Usage of Generic Class:  LinkedList<Integer> ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example: Definition and Usage of Parameterized List interface ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why Generics?  Non-genericized Code is not Type Safe // Suppose you want to maintain String  // entries in a Vector.  By mistake,  // you add an Integer element.  Compiler  // does not detect this.  This is not //  type safe code . Vector v = new Vector(); v.add(new String(“valid string”)); // intended v.add(new  Integer (4));  // unintended //  ClassCastException occurs during runtime String s = (String)v.get(0);
Why Generics?  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generics: Usage of Generics
Using Generic Classes: Example 1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Generic Classes: Example 2 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generics: Sub-typing
Generics and Sub-typing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generics and Sub-typing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generics and Sub-typing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generics and Sub-typing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generics: Wild card
Why Wildcards?  Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why Wildcards?  Problem ,[object Object],static void printCollection(Collection <Object>  c) { for (Object o : c)  System.out.println(o); } public static void main(String[] args) { Collection<String> cs = new Vector<String>(); printCollection(cs); // Compile error  List<Integer> li = new ArrayList<Integer>(10); printCollection(li); // Compile error   }
Why Wildcards?  Solution ,[object Object],[object Object],[object Object],static void printCollection(Collection <?>  c) { for ( Object  o : c)  System.out.println(o); } public static void main(String[] args) { Collection<String> cs = new Vector<String>(); printCollection(cs); // No Compile error   List<Integer> li = new ArrayList<Integer>(10); printCollection(li); // No Compile error   }
More on Wildcards ,[object Object],static void printCollection(Collection <?>  c) { for ( String  o : c)  // Compile error System.out.println(o); } public static void main(String[] args) { Collection<String> cs = new Vector<String>(); printCollection(cs); // No Compile error   List<Integer> li = new ArrayList<Integer>(10); printCollection(li); // No Compile error   }
More on Wildcards ,[object Object],static void printCollection(Collection <?>  c) { c.add(new Object()); // Compile time error  c.add(new String()); // Compile time error   } public static void main(String[] args) { Collection<String> cs = new Vector<String>(); printCollection(cs); // No Compile error   List<Integer> li = new ArrayList<Integer>(10); printCollection(li); // No Compile error   }
Bounded Wildcard ,[object Object],static void printCollection( Collection <? extends Number>  c) { for (Object o : c)  System.out.println(o); } public static void main(String[] args) { Collection<String> cs = new Vector<String>(); printCollection(cs); // Compile error  List<Integer> li = new ArrayList<Integer>(10); printCollection(li); // No Compile error   }
Generics: Raw Type &  Type Erasure
Raw Type ,[object Object],[object Object],// Generic type instantiated with type argument List<String> ls = new LinkedList<String>(); // Generic type instantiated with no type  // argument – This is Raw type List lraw = new LinkedList();
Type Erasure ,[object Object],[object Object],[object Object],[object Object]
Type Erasure Example Code:  True or False? ,[object Object],[object Object],[object Object],[object Object]
Type-safe Code Again  ,[object Object],[object Object],[object Object],[object Object],[object Object]
Generics: Interoperability
What Happens to the following Code? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Compilation and Running ,[object Object],[object Object],[object Object],[object Object]
Generics: Creating Your Own Generic Class
Defining Your Own Generic Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Your Own Generic Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Annotation
Sub-topics of Annotations ,[object Object],[object Object],[object Object],[object Object]
How Annotation Are Used? ,[object Object],[object Object],[object Object],[object Object]
Ad-hoc Annotation-like Examples in pre-J2SE 5.0 Platform ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why Annotation? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Annotation: How do you define & use annotations?
How to “Define” Annotation Type?  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example: Annotation Type Definition ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How To “Use” Annotation  ,[object Object],[object Object],[object Object],[object Object],[object Object]
Example: Usage of Annotation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Annotation: 3 Types of Annotations (in terms of Sophistication)
3 Different Kinds of Annotations ,[object Object],[object Object],[object Object]
Marker Annotation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Single Value Annotation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Normal Annotation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Annotation: Meta-Annotations
@Retention Meta-Annotation ,[object Object],[object Object],[object Object],[object Object],[object Object]
@Target Meta-Annotation  ,[object Object],[object Object],[object Object]
Example: Definition and Usage of an Annotation with Meta Annotation  Definition of Accessor annotation @Target (ElementType.FIELD) @Retention (RetentionPolicy.CLASS) public  @interface  Accessor { String variableName(); String variableType()  default  &quot;String&quot;; } Usage Example of the Accessor annotation @Accessor(variableName = &quot;name&quot;) public String myVariable;
Reflection  ,[object Object],[object Object]
Reflection  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Concurrency
Concurrency Utilities: JSR-166 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why Use Concurrency Utilities? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Concurrency Utilities ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Concurrency: Task Scheduling  Framework
Task Scheduling Framework  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Executor Interface  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Executor and ExecutorService ,[object Object],[object Object],ExecutorService adds lifecycle management
Creating ExecutorService From Executors ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
pre-J2SE 5.0 Code ,[object Object],[object Object],Web Server—poor resource management
Executors Example ,[object Object],[object Object],[object Object],Web Server—better resource management
Concurrency: Callables and Futures
Callable's and Future's:  Problem (pre-J2SE 5.0) ,[object Object],[object Object]
Callables and Futures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Build CallableExample  (This is Callee) class CallableExample  implements  Callable< String >  { public  String   call()  { String result = “The work is ended”; /*  Do some work and create a result  */ return result; } }
Future Example (Caller) ExecutorService es =  Executors.newSingleThreadExecutor(); Future<String> f   =  es.submit(new CallableExample()); /*  Do some work in parallel  */ try { String callableResult = f.get(); } catch (InterruptedException ie) { /*  Handle  */ } catch (ExecutionException ee) { /*  Handle  */ }
Concurrency: Synchronizers: Semaphore
Semaphores ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Semaphore Example private  Semaphore available ; private Resource[] resources; private boolean[] used; public Resource(int poolSize) { available = new  Semaphore(poolSize) ; /*  Initialise resource pool  */ } public Resource getResource() { try {  available.aquire()  } catch (IE) {} /*  Acquire resource  */ } public void returnResource(Resource r) { /*  Return resource to pool  */ available.release() ; }
Concurrency: Concurrent Collections
BlockingQueue Interface ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Blocking Queue Example: Logger placing log messages private  ArrayBlockingQueue messageQueue =  new ArrayBlockingQueue<String>(10); Logger logger = new Logger( messageQueue ); public void run() { String someMessage; try { while (true) { /*  Do some processing  */ /*  Blocks if no space available  */ messageQueue.put(someMessage) ; } } catch (InterruptedException ie) { } }
Blocking Queue Example: Log Reader reading log messages private  BlockingQueue<String>  msgQueue; public LogReader( BlockingQueue<String>  mq){ msgQueue = mq; } public void run() { try { while (true) { String message =  msgQueue.take (); /*  Log message  */ } } catch (InterruptedException ie) {  /*  Handle  */ } }
Concurrency: Atomic Variables
Atomics ,[object Object],[object Object],AtomicInteger balance = new AtomicInteger(0); public int deposit(integer amount) { return balance.addAndGet(amount); }
Concurrency: Locks
Locks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ReadWriteLock ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ReadWrite Lock Example class ReadWriteMap { final Map<String, Data> m = new TreeMap<String, Data>(); final  ReentrantReadWriteLock rwl =  new ReentrantReadWriteLock (); final  Lock r = rwl.readLock(); final  Lock w = rwl.writeLock(); public Data get(String key) { r.lock(); try { return m.get(key) }   finally {  r.unlock();  } } public Data put(String key, Data value) { w.lock(); try { return m.put(key, value); } finally {  w.unlock();  } } public void clear() { w.lock(); try { m.clear(); } finally {  w.unlock();  } } }
JMX (Java Management Extension)
JMX Introduction ,[object Object],[object Object],[object Object],[object Object]
What is JMX? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JMX: Architecture
JMX Architecture ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JMX Architecture Courtsey: Borislav Iordanov
JMX Architecture Application JMX Agent Manages Remote Manager
JMX: MBean
Managed Beans(MBeans) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A MBean Example  CacheControlMBean Used: int Size:  int save(): void dropOldest(int n): int attributes operations “ com.example.config.change” “ com.example.cache.full” notifications R RW
Standard MBean ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dynamic MBean ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DynamicMBean Interface <<Interface>> DynamicMBean getMBeanInfo():MBeanInfo getAttribute(attribute:String):Object getAttributes(attributes:String[]):AttributeList setAttribute(attribute:Attribute):void setAttributes(attributes:AttributeList):AttributeList invoke(actionName:String, params:Object[], signature:String[]):Object
JMX Notification ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JMX: MBean Server
MBean Server  MBean Server CacheControlMBean com.example:type=CacheControl …
MBean Server ,[object Object],[object Object],[object Object],[object Object],[object Object]
JMX: Client Types
MBean Server: Local Clients MBean Server
MBean Server: Connector Client MBean Server RMI, IIOP, ...
MBean Server: Connector ,[object Object],[object Object],[object Object],[object Object],[object Object]
MBean Server: Adaptor Client MBean Server SNMP, HTML, ...
Mapping SNMP or CIM to JMX API SNMP MIB/ CIM model generation tool skeleton MBeans implement semantics final MBeans ,[object Object],[object Object],[object Object],[object Object]
JMX: JMX API Services
JMX API Services ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JMX: Steps of instrumenting  Your Application
Steps for Instrumenting Your App ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JMX: Demo – Running  Anagram application with JMX support
Demo Scenario ,[object Object],[object Object],[object Object],[object Object]
Java SE Beyond Basics:  Generics, Annotation, JMX Sang Shin [email_address] www.javapassion.com Sun Microsystems Inc.
Instrument ClickCounter  (Standard MBean) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Accessing the JMX Agent ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Standard Mbean Interface public  interface   ClickCounterStdMBean  { public void reset(); public int getDisplayNumber(); public void setDisplayNumber(int inNumber); public int getCountNumber(); }
Implements Standard MBean public class ClickCounterStd  extends   ClickFrame implements   ClickCounterStdMBean  { public void reset() { getModel().reset(); updateLabel(); } public int getDisplayNumber() { returngetModel().getDisplayNumber(); } . . . . . . }
Registering a MBean ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JMX: Roadmap
What's coming next? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JMX API Versions JSR 3: JMX API 1.0 1.1 1.2 (1.2) 1.0 JSR 160: JMX Remote API JSR 255: JMX API (1.0) 2.0 1.0 JSR 262: Web Services Connector ,[object Object],You are here
MXBeans: Problem Statement (1) ,[object Object],[object Object],public interface ThreadMBean {   public  ThreadInfo  getThreadInfo(); } public class  ThreadInfo  {   public String getName();   public long getBlockedCount();   public boolean isSuspended();   ... }
MXBeans: Problem Statement (2) ,[object Object],[object Object],[object Object],[object Object],public interface ThreadMBean {   public  ThreadInfo  getThreadInfo(); }
MXBeans (1) ,[object Object],[object Object],[object Object],[object Object],[object Object]
MXBeans (2) public interface Thread MXBean  { public ThreadInfo getThreadInfo(); } public class  ThreadMXBeanImpl   implements   ThreadMXBean { // Do not need  Something / Something MXBean naming public ThreadInfo getThreadInfo() { return new ThreadInfo(...); } } ThreadMXBean mxbean = new ThreadMXBeanImpl(); ObjectName name = new ObjectName(&quot;java.lang:type=Threading&quot;); mbs.registerMBean(mxbean, name);
MXBeans (3) MBean Server ,[object Object],[object Object],ThreadMXBean ThreadInfo CompositeData Generic Client ThreadInfo ThreadMXBean Proxy unconvert CompositeData Open MBean Wrapper convert ThreadMXBean ThreadInfo
MXBean References (1) ProductMXBean ModuleMXBean ModuleMXBean[ ] public interface ProductMXBean { ModuleMXBean[] getModules(); }
MXBean References (2) MBean Server ModuleMXBean ProductMXBean ModuleMXBean[ ] ObjectName[ ] “ P1” “ M1” “ M2” ModuleMXBean ProductMXBean ModuleMXBean[ ] Generic Client ObjectName[ ] {“M1”, “M2”} “ P1” ModuleMXBean Proxy ModuleMXBean[ ] ProductMXBean Proxy
MXBean References (3) Modules Products Licenses Navigating From a Starting Point ProductMXBean ModuleMXBean InstallationManagerMXBean LicenseMXBean
Descriptors CacheControlMBean Used: int Size:  int save(): void dropOldest(int n): int “ com.example.config.change” “ com.example.cache.full” R RW severity 5 units minValue maxValue since “ whatsits” 0 16 “2.3” version designer “ 2.5” “ data model group”
Descriptors and Generic Clients 0 16 whatsits Used Used: int R units minValue maxValue “ whatsits” 0 16 (like jconsole)
Descriptor Details ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Descriptor Annotations ,[object Object],[object Object],[object Object],Used: int R units minValue maxValue “ whatsits” 0 16
Some Other Mustang changes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JMX Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Performance
GC  A lgorithms ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Mark-Sweep Collector ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Copying Collector ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
HotSpot Heap Layout Tenured Space Permanent Space Permanent Generation Old Generation Young Generation Eden Space From  Space To  Space Survivor Ratio (2Mb default) (64Kb default) (5Mb min, 44Mb max default)
General Tuning Advice ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Throughput Collector ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Concurrent Collector ,[object Object],[object Object],[object Object],[object Object]
Resources ,[object Object],[object Object],[object Object]

More Related Content

What's hot

Javase5generics
Javase5genericsJavase5generics
Javase5genericsimypraz
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaRasan Samarasinghe
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingKeshav Kumar
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Threeamiable_indian
 
Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.Vadim Dubs
 
Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityMohd Sajjad
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)rnkhan
 
Effective Java Second Edition
Effective Java Second EditionEffective Java Second Edition
Effective Java Second Editionlosalamos
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NETRasan Samarasinghe
 
DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#Rasan Samarasinghe
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Andrew Petryk
 

What's hot (18)

M C6java7
M C6java7M C6java7
M C6java7
 
M C6java3
M C6java3M C6java3
M C6java3
 
Javase5generics
Javase5genericsJavase5generics
Javase5generics
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in Java
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 
Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.
 
DITEC - Programming with Java
DITEC - Programming with JavaDITEC - Programming with Java
DITEC - Programming with Java
 
Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutability
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Effective Java Second Edition
Effective Java Second EditionEffective Java Second Edition
Effective Java Second Edition
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NET
 
DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)
 

Viewers also liked

Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDBOliver Gierke
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2Haroon Idrees
 
Spring Framework - Validation
Spring Framework - ValidationSpring Framework - Validation
Spring Framework - ValidationDzmitry Naskou
 
Spring Framework - Data Access
Spring Framework - Data AccessSpring Framework - Data Access
Spring Framework - Data AccessDzmitry Naskou
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVCJohn Lewis
 
Spring Framework - Web Flow
Spring Framework - Web FlowSpring Framework - Web Flow
Spring Framework - Web FlowDzmitry Naskou
 
Spring Framework - Expression Language
Spring Framework - Expression LanguageSpring Framework - Expression Language
Spring Framework - Expression LanguageDzmitry Naskou
 
Spring mvc my Faviourite Slide
Spring mvc my Faviourite SlideSpring mvc my Faviourite Slide
Spring mvc my Faviourite SlideDaniel Adenew
 
Spring 3 Annotated Development
Spring 3 Annotated DevelopmentSpring 3 Annotated Development
Spring 3 Annotated Developmentkensipe
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring DataArturs Drozdovs
 
Java Annotation
Java AnnotationJava Annotation
Java Annotationip-imamoto
 
Annotating Text: A Powerful Reading Tool
Annotating Text: A Powerful Reading ToolAnnotating Text: A Powerful Reading Tool
Annotating Text: A Powerful Reading ToolPamela Santerre
 

Viewers also liked (20)

Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDB
 
Java annotation
Java annotationJava annotation
Java annotation
 
Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5
 
Coding standard
Coding standardCoding standard
Coding standard
 
Java annotations
Java annotationsJava annotations
Java annotations
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
Spring Framework - Validation
Spring Framework - ValidationSpring Framework - Validation
Spring Framework - Validation
 
Spring Framework - Data Access
Spring Framework - Data AccessSpring Framework - Data Access
Spring Framework - Data Access
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Junit
JunitJunit
Junit
 
Spring Framework - Web Flow
Spring Framework - Web FlowSpring Framework - Web Flow
Spring Framework - Web Flow
 
Java Annotation
Java AnnotationJava Annotation
Java Annotation
 
Spring Framework - Expression Language
Spring Framework - Expression LanguageSpring Framework - Expression Language
Spring Framework - Expression Language
 
Annotations
AnnotationsAnnotations
Annotations
 
Spring mvc my Faviourite Slide
Spring mvc my Faviourite SlideSpring mvc my Faviourite Slide
Spring mvc my Faviourite Slide
 
Understanding Annotations in Java
Understanding Annotations in JavaUnderstanding Annotations in Java
Understanding Annotations in Java
 
Spring 3 Annotated Development
Spring 3 Annotated DevelopmentSpring 3 Annotated Development
Spring 3 Annotated Development
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
Java Annotation
Java AnnotationJava Annotation
Java Annotation
 
Annotating Text: A Powerful Reading Tool
Annotating Text: A Powerful Reading ToolAnnotating Text: A Powerful Reading Tool
Annotating Text: A Powerful Reading Tool
 

Similar to javasebeyondbasics

Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminarGautam Roy
 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Featurestarun308
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancementRakesh Madugula
 
Java 7 new features
Java 7 new featuresJava 7 new features
Java 7 new featuresShivam Goel
 
Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Peter Antman
 
Generics Collections
Generics CollectionsGenerics Collections
Generics Collectionsphanleson
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationRandy Connolly
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrongJulien Wetterwald
 
Applying Generics
Applying GenericsApplying Generics
Applying GenericsBharat17485
 
Evolving The Java Language
Evolving The Java LanguageEvolving The Java Language
Evolving The Java LanguageQConLondon2008
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingKeshav Kumar
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side JavascriptJulie Iskander
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003R696
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the BasicsJussi Pohjolainen
 

Similar to javasebeyondbasics (20)

Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminar
 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Features
 
Java Generics
Java GenericsJava Generics
Java Generics
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
 
Java 7 new features
Java 7 new featuresJava 7 new features
Java 7 new features
 
Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)
 
Generics Collections
Generics CollectionsGenerics Collections
Generics Collections
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrong
 
Collections
CollectionsCollections
Collections
 
Applying Generics
Applying GenericsApplying Generics
Applying Generics
 
Evolving The Java Language
Evolving The Java LanguageEvolving The Java Language
Evolving The Java Language
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the Basics
 

More from webuploader

Michael_Hulme_Banff_Social_Networking
Michael_Hulme_Banff_Social_NetworkingMichael_Hulme_Banff_Social_Networking
Michael_Hulme_Banff_Social_Networkingwebuploader
 
cyberSecurity_Milliron
cyberSecurity_MillironcyberSecurity_Milliron
cyberSecurity_Millironwebuploader
 
LiveseyMotleyPresentation
LiveseyMotleyPresentationLiveseyMotleyPresentation
LiveseyMotleyPresentationwebuploader
 
FairShare_Morningstar_022607
FairShare_Morningstar_022607FairShare_Morningstar_022607
FairShare_Morningstar_022607webuploader
 
3_System_Requirements_and_Scaling
3_System_Requirements_and_Scaling3_System_Requirements_and_Scaling
3_System_Requirements_and_Scalingwebuploader
 
ScalabilityAvailability
ScalabilityAvailabilityScalabilityAvailability
ScalabilityAvailabilitywebuploader
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practiceswebuploader
 
7496_Hall 070204 Research Faculty Summit
7496_Hall 070204 Research Faculty Summit7496_Hall 070204 Research Faculty Summit
7496_Hall 070204 Research Faculty Summitwebuploader
 
FreeBSD - LinuxExpo
FreeBSD - LinuxExpoFreeBSD - LinuxExpo
FreeBSD - LinuxExpowebuploader
 

More from webuploader (20)

Michael_Hulme_Banff_Social_Networking
Michael_Hulme_Banff_Social_NetworkingMichael_Hulme_Banff_Social_Networking
Michael_Hulme_Banff_Social_Networking
 
socialpref
socialprefsocialpref
socialpref
 
cyberSecurity_Milliron
cyberSecurity_MillironcyberSecurity_Milliron
cyberSecurity_Milliron
 
PJO-3B
PJO-3BPJO-3B
PJO-3B
 
LiveseyMotleyPresentation
LiveseyMotleyPresentationLiveseyMotleyPresentation
LiveseyMotleyPresentation
 
FairShare_Morningstar_022607
FairShare_Morningstar_022607FairShare_Morningstar_022607
FairShare_Morningstar_022607
 
saito_porcupine
saito_porcupinesaito_porcupine
saito_porcupine
 
3_System_Requirements_and_Scaling
3_System_Requirements_and_Scaling3_System_Requirements_and_Scaling
3_System_Requirements_and_Scaling
 
ScalabilityAvailability
ScalabilityAvailabilityScalabilityAvailability
ScalabilityAvailability
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practices
 
7496_Hall 070204 Research Faculty Summit
7496_Hall 070204 Research Faculty Summit7496_Hall 070204 Research Faculty Summit
7496_Hall 070204 Research Faculty Summit
 
Chapter5
Chapter5Chapter5
Chapter5
 
Mak3
Mak3Mak3
Mak3
 
visagie_freebsd
visagie_freebsdvisagie_freebsd
visagie_freebsd
 
freebsd-watitis
freebsd-watitisfreebsd-watitis
freebsd-watitis
 
BPotter-L1-05
BPotter-L1-05BPotter-L1-05
BPotter-L1-05
 
FreeBSD - LinuxExpo
FreeBSD - LinuxExpoFreeBSD - LinuxExpo
FreeBSD - LinuxExpo
 
CLI313
CLI313CLI313
CLI313
 
CFInterop
CFInteropCFInterop
CFInterop
 
WCE031_WH06
WCE031_WH06WCE031_WH06
WCE031_WH06
 

Recently uploaded

ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 

Recently uploaded (20)

ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 

javasebeyondbasics

  • 1. Java SE Beyond Basics: Generics, Annotation, Concurrency, and JMX Sang Shin [email_address] www.javapassion.com Sun Microsystems Inc.
  • 2.
  • 3.
  • 5.
  • 6. Generics: What is it? How do define it? How to use it? Why use it?
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Why Generics? Non-genericized Code is not Type Safe // Suppose you want to maintain String // entries in a Vector. By mistake, // you add an Integer element. Compiler // does not detect this. This is not // type safe code . Vector v = new Vector(); v.add(new String(“valid string”)); // intended v.add(new Integer (4)); // unintended // ClassCastException occurs during runtime String s = (String)v.get(0);
  • 12.
  • 13. Generics: Usage of Generics
  • 14.
  • 15.
  • 17.
  • 18.
  • 19.
  • 20.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. Generics: Raw Type & Type Erasure
  • 29.
  • 30.
  • 31.
  • 32.
  • 34.
  • 35.
  • 36. Generics: Creating Your Own Generic Class
  • 37.
  • 38.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44. Annotation: How do you define & use annotations?
  • 45.
  • 46.
  • 47.
  • 48.
  • 49. Annotation: 3 Types of Annotations (in terms of Sophistication)
  • 50.
  • 51.
  • 52.
  • 53.
  • 55.
  • 56.
  • 57. Example: Definition and Usage of an Annotation with Meta Annotation Definition of Accessor annotation @Target (ElementType.FIELD) @Retention (RetentionPolicy.CLASS) public @interface Accessor { String variableName(); String variableType() default &quot;String&quot;; } Usage Example of the Accessor annotation @Accessor(variableName = &quot;name&quot;) public String myVariable;
  • 58.
  • 59.
  • 61.
  • 62.
  • 63.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 72.
  • 73.
  • 74. Build CallableExample (This is Callee) class CallableExample implements Callable< String > { public String call() { String result = “The work is ended”; /* Do some work and create a result */ return result; } }
  • 75. Future Example (Caller) ExecutorService es = Executors.newSingleThreadExecutor(); Future<String> f = es.submit(new CallableExample()); /* Do some work in parallel */ try { String callableResult = f.get(); } catch (InterruptedException ie) { /* Handle */ } catch (ExecutionException ee) { /* Handle */ }
  • 77.
  • 78. Semaphore Example private Semaphore available ; private Resource[] resources; private boolean[] used; public Resource(int poolSize) { available = new Semaphore(poolSize) ; /* Initialise resource pool */ } public Resource getResource() { try { available.aquire() } catch (IE) {} /* Acquire resource */ } public void returnResource(Resource r) { /* Return resource to pool */ available.release() ; }
  • 80.
  • 81. Blocking Queue Example: Logger placing log messages private ArrayBlockingQueue messageQueue = new ArrayBlockingQueue<String>(10); Logger logger = new Logger( messageQueue ); public void run() { String someMessage; try { while (true) { /* Do some processing */ /* Blocks if no space available */ messageQueue.put(someMessage) ; } } catch (InterruptedException ie) { } }
  • 82. Blocking Queue Example: Log Reader reading log messages private BlockingQueue<String> msgQueue; public LogReader( BlockingQueue<String> mq){ msgQueue = mq; } public void run() { try { while (true) { String message = msgQueue.take (); /* Log message */ } } catch (InterruptedException ie) { /* Handle */ } }
  • 84.
  • 86.
  • 87.
  • 88. ReadWrite Lock Example class ReadWriteMap { final Map<String, Data> m = new TreeMap<String, Data>(); final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock (); final Lock r = rwl.readLock(); final Lock w = rwl.writeLock(); public Data get(String key) { r.lock(); try { return m.get(key) } finally { r.unlock(); } } public Data put(String key, Data value) { w.lock(); try { return m.put(key, value); } finally { w.unlock(); } } public void clear() { w.lock(); try { m.clear(); } finally { w.unlock(); } } }
  • 89. JMX (Java Management Extension)
  • 90.
  • 91.
  • 93.
  • 94. JMX Architecture Courtsey: Borislav Iordanov
  • 95. JMX Architecture Application JMX Agent Manages Remote Manager
  • 97.
  • 98. A MBean Example CacheControlMBean Used: int Size: int save(): void dropOldest(int n): int attributes operations “ com.example.config.change” “ com.example.cache.full” notifications R RW
  • 99.
  • 100.
  • 101. DynamicMBean Interface <<Interface>> DynamicMBean getMBeanInfo():MBeanInfo getAttribute(attribute:String):Object getAttributes(attributes:String[]):AttributeList setAttribute(attribute:Attribute):void setAttributes(attributes:AttributeList):AttributeList invoke(actionName:String, params:Object[], signature:String[]):Object
  • 102.
  • 104. MBean Server MBean Server CacheControlMBean com.example:type=CacheControl …
  • 105.
  • 107. MBean Server: Local Clients MBean Server
  • 108. MBean Server: Connector Client MBean Server RMI, IIOP, ...
  • 109.
  • 110. MBean Server: Adaptor Client MBean Server SNMP, HTML, ...
  • 111.
  • 112. JMX: JMX API Services
  • 113.
  • 114. JMX: Steps of instrumenting Your Application
  • 115.
  • 116. JMX: Demo – Running Anagram application with JMX support
  • 117.
  • 118. Java SE Beyond Basics: Generics, Annotation, JMX Sang Shin [email_address] www.javapassion.com Sun Microsystems Inc.
  • 119.
  • 120.
  • 121. Standard Mbean Interface public interface ClickCounterStdMBean { public void reset(); public int getDisplayNumber(); public void setDisplayNumber(int inNumber); public int getCountNumber(); }
  • 122. Implements Standard MBean public class ClickCounterStd extends ClickFrame implements ClickCounterStdMBean { public void reset() { getModel().reset(); updateLabel(); } public int getDisplayNumber() { returngetModel().getDisplayNumber(); } . . . . . . }
  • 123.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130. MXBeans (2) public interface Thread MXBean { public ThreadInfo getThreadInfo(); } public class ThreadMXBeanImpl implements ThreadMXBean { // Do not need Something / Something MXBean naming public ThreadInfo getThreadInfo() { return new ThreadInfo(...); } } ThreadMXBean mxbean = new ThreadMXBeanImpl(); ObjectName name = new ObjectName(&quot;java.lang:type=Threading&quot;); mbs.registerMBean(mxbean, name);
  • 131.
  • 132. MXBean References (1) ProductMXBean ModuleMXBean ModuleMXBean[ ] public interface ProductMXBean { ModuleMXBean[] getModules(); }
  • 133. MXBean References (2) MBean Server ModuleMXBean ProductMXBean ModuleMXBean[ ] ObjectName[ ] “ P1” “ M1” “ M2” ModuleMXBean ProductMXBean ModuleMXBean[ ] Generic Client ObjectName[ ] {“M1”, “M2”} “ P1” ModuleMXBean Proxy ModuleMXBean[ ] ProductMXBean Proxy
  • 134. MXBean References (3) Modules Products Licenses Navigating From a Starting Point ProductMXBean ModuleMXBean InstallationManagerMXBean LicenseMXBean
  • 135. Descriptors CacheControlMBean Used: int Size: int save(): void dropOldest(int n): int “ com.example.config.change” “ com.example.cache.full” R RW severity 5 units minValue maxValue since “ whatsits” 0 16 “2.3” version designer “ 2.5” “ data model group”
  • 136. Descriptors and Generic Clients 0 16 whatsits Used Used: int R units minValue maxValue “ whatsits” 0 16 (like jconsole)
  • 137.
  • 138.
  • 139.
  • 140.
  • 142.
  • 143.
  • 144.
  • 145. HotSpot Heap Layout Tenured Space Permanent Space Permanent Generation Old Generation Young Generation Eden Space From Space To Space Survivor Ratio (2Mb default) (64Kb default) (5Mb min, 44Mb max default)
  • 146.
  • 147.
  • 148.
  • 149.