SlideShare une entreprise Scribd logo
1  sur  51
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.1
JSR 236: Introduction to
Concurrency Utilities for
Java EE 1.0
Anthony Lai
Oracle
Fred Rowe
IBM
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.3
The following is intended to outline our general product direction. It is intended
for information purposes only, and may not be incorporated into any contract.
It is not a commitment to deliver any material, code, or functionality, and should
not be relied upon in making purchasing decisions. The
development, release, and timing of any features or functionality described for
Oracle’s products remains at the sole discretion of Oracle.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.4
Program Agenda
 Overview
 Managed Objects
 Features
 Summary
 Resources
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.5
Overview
 Provide a simple and flexible standard API for application component
providers to design applications using concurrency design principles
 Provide a simple migration path from Java SE Concurrency Utilities
(JSR-166) to the Java EE platform by providing consistency between
the two platforms
 Allow application component providers to easily add concurrency to
existing Java EE applications
 Support simple and advanced concurrency patterns without sacrificing
usability
Goals
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.6
Overview
 2003 – JSR 236 and JSR237 filed. CommonJ API provides context
aware Work Managers and Timers to Java EE applications
 2006 – CommonJ API replaced by API that extends from Java SE
concurrency utilities
 2008 – Merged into JSR 236
 2008 – 2012 …
 2012 – JSR 236 restarted
 2013 – JSR 236 released and become part of Java EE 7
History
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.7
Overview
 Simple, standardized API for using concurrency from application
components
 Extension of Java SE Concurrency Utilities APIs (JSR-166)
 Provide low-level asynchronous processing capabilities to Java EE
application components in a safe, reliable, consistent manner
 Manage and monitor the lifecycle of asynchronous operations
Main Features
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.8
Overview
 Provides 4 types of managed objects that implement these interfaces
in javax.enterprise.concurrent package:
– ManagedExecutorService
– ManagedScheduledExecutorService
– ManagedThreadFactory
– ContextService
 Container context propagation
 Transaction management
 Task events notification
Main Features
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.9
Program Agenda
 Overview
 Managed Objects
 Features
 Summary
 Resources
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.10
Managed Objects
 Managed Objects are provided by the Java EE Product Provider
 Applications access managed objects by
– JNDI lookup
– resource injection using @Resource
 Configurable
 Pre-configured default managed objects are available
– e.g. java:comp/DefaultManagedThreadFactory
Overview
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.11
ManagedThreadFactory
 A standard way for applications to obtain a container-managed
threads from Java EE Containers
 Supports context propagation
 Can be used with asynchronous processing API in Servlets
 Can be used for creating custom executors in advanced use cases
Overview
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.12
ManagedThreadFactory
 Interface extends from java.util.concurrent.ThreadFactory
– Same API: Thread.newThread(Runnable)
– Container context captured at ManagedThreadFactory creation
will be propagated to the thread returned
 Threads returned by newThread() method are required to implement
the ManagableThread interface
– boolean isShutdown()
 Can be used with Java SE concurrency utilities APIs where
ThreadFactory is needed. e.g. in
java.util.concurrent.Executors
API
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.13
ManagedThreadFactory
 Thread interrupted when ManagedThreadFactory shuts down
 Runnable implementations should check
ManagableThread.isShutdown() when interrupted
– clean up if it returns true
Shutdown
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.14
ManagedThreadFactory
// Create a ThreadPoolExecutor using a ManagedThreadFactory.
@Resource ManagedThreadFactory tf;
public ExecutorService getManagedThreadPool() {
// All threads will run as part of this application component.
return new ThreadPoolExecutor(5, 10, 5, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(10), tf);
}
Example 1
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.15
ManagedThreadFactory
@WebServlet(asyncSupported=true)
public class TestServlet extends HttpServlet {
@Resource private ManagedThreadFactory managedThreadFactory;
protected void doGet(HttpServletRequest
req, HttpServletResponse res {
final AsyncContext asyncContext = req.startAsync();
…
Runnable runnable = new Runnable() {
public void run() {
…
asyncContext.complete();
}
};
Thread thread = managedThreadFactory.newThread(runnable);
thread.start();
…
}
}
Example 2 – Use with Asynchronous Servlet
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.16
ManagedExecutorService
 For running tasks asynchronously on threads provided by Java EE
product provider
– Tasks must implement either java.util.concurrent.Callable or
java.lang.Runnable
 Supports context propagation
 Allow application developers to use familiar Java SE APIs for
concurrent processing of tasks in Java EE
Overview
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.17
ManagedExecutorService
 Extends from java.util.concurrent.ExecutorService
– execute, submit, invokeAll, invokeAny
– No new APIs
 Future is returned upon task submission
– Checks for the task execution status
– Cancels the task
– Waits and retrieves result
 Lifecycle APIs disabled – throws IllegalStateException
– awaitTermination, isTerminated, isShutdown, shutdown, shutd
ownNow
API
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.18
ManagedExecutorService
Example 1
@Resource ManagedExecutorService mes;
void someMethod() {
Callable<Integer> c = new Callable<>() {
Integer call() {
// Interact with a database...return answer.
}
//Submit the task and do something else.
Future result = mes.submit(c);
...
//Get the result when ready...
int theValue = result.get();
...
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.19
ManagedExecutorService
Example 2 – Use with Asynchronous Servlet
@WebServlet(asyncSupported=true)
public class TestAsyncMESServlet extends HttpServlet {
@Resource private ManagedExecutorService
managedExecutorService;
protected void doGet(HttpServletRequest
req, HttpServletResponse res {
final AsyncContext asyncContext = req.startAsync();
…
Runnable runnable = new Runnable() {
public void run() {
…
asyncContext.complete();
}
};
managedExecutorService.submit(runnable);
…
}
}
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.20
ManagedExecutorService
Managed Thread Pool Executor Component Relationship
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.21
ManagedScheduledExecutorService
 For scheduling tasks to run
– after a given delay
– periodically
– at some custom schedule
 Tasks are run on threads that are provided by the Java EE container
 Supports context propagation
 Allows application developers to use familiar Java SE APIs for
submitting scheduled tasks in Java EE
Overview
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.22
ManagedScheduledExecutorService
 Extends from ManagedExecutorService
 Extends from
java.util.concurrent.ScheduledExecutorService
– schedule, scheduleAtFixedRate, scheduleWithFixedDelay
 Lifecycle APIs disabled – throws IllegalStateException
– awaitTermination, isTerminated, isShutdown, shutdown, shutd
ownNow
 Extension API to support custom scheduling
– schedule with Trigger
API
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.23
ManagedScheduledExecutorService
API from ScheduledExecutorService
<V> ScheduledFuture<V> schedule(Callable<V> callable, long delay,
TimeUnit unit);
ScheduledFuture<?> schedule(Runnable command, long delay,
TimeUnit unit);
ScheduledFuture<?> scheduleAtFixedFate(Runnable command,
long initialDelay, long period, TimeUnit unit);
ScheduledFuture<?> scheduledWithFixedDelay(Runnable command,
long initialDelay, long delay, TimeUnit unit);
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.24
ManagedScheduledExecutorService
API for Custom Scheduling
<V> ScheduledFuture<V> schedule(Callable<V> callable, Trigger trigger);
ScheduledFuture<?> schedule(Runnable command, Trigger trigger);
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.25
ManagedScheduledExecutorService
Trigger
 For supporting custom scheduling rules
– Can be simple: single, absolute date/time
– Can be complex calendar logic
– Next trigger time can be calculated based on previous trigger execution
date/time and result
 Implemented by application developers
 Submitted along with a task using the schedule method in
ManagedScheduledExecutorService
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.26
ManagedScheduledExecutorService
Trigger API
boolean skipRun(LastExecution lastExecutionInfo,
Date scheduledRunTime)
Date getNextRunTime(LastExecution
lastExecutionInfo, Date taskScheduledTime)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.27
ManagedScheduledExecutorService
Trigger Example
public class SimpleFixedDateTrigger implements Trigger {
private Date fireTime;
public SimpleFixedDateTrigger(Date triggerDate) {
fireTime = triggerDate;
}
public Date getNextRunTime(
LastExecution lastExecutionInfo, Date taskScheduledTime) {
if(taskScheduledTime.after(fireTime)) {
return null;
}
return fireTime;
}
public boolean skipRun(LastExecution lastExecutionInfo, Date
scheduledRunTime) {
return scheduledRunTime.after(fireTime);
}
}
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.28
ContextService
 For creating contextual proxy objects
– Application context is captured upon creation
– Proxy object methods will run within the captured context at a later time
 For use in advanced use cases
– E.g. to propagate user identity
– E.g. to request task listener notifications to be run under container context
 Uses dynamic proxy mechanism in java.lang.reflect package
Overview
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.29
ContextService
 Contextual proxy objects customizable through execution properties
– Transaction property
– Vendor specific properties, e.g. vendorA.security_token_expiration
 API for returning the execution properties on the given contextual
object proxy instance
– Map<String,String> getExecutionProperties(Object
contextualProxy)
Execution Properties
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.30
ContextService
 For creating contextual proxy objects:
– <T> T createContextualProxy(T instance, Class<T> intf)
– Object createContextualProxy(Object
instance, Class<?>... Interfaces)
– <T> T createContextualProxy(T
instance, Map<String,String>
executionProperties, Class<T> intf)
– Object createContextualProxy(Object
instance, Map<String,String>
executionProperties, Class<?>... Interfaces)
API
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.31
ContextService
Example 1
@Resource ContextService ctxSvc;
MyAppIntf proxy =
ctxSvc.createContextualProxy (myAppImpl, MyAppIntf.class);
// invoke at a later time, possibly in a different app
// component
proxy.doSomething();
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.32
ContextService
Example 2
// In application
public interface MessageProcessor {
public void processMessage(Message msg)
…
}
// Within servlet or EJB method…
@Resource ContextService ctxSvc;
void businessMethod() {
MessageProcessor msgProcessor = …
// Wrap with the current context
MessageProcessor proxy = ctxSvc.createContextualProxy
(msgProcessor, MessageProcessor.class);
// Store the contextual proxy object somewhere for running later.
store.putIt(proxy);
…
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.33
ContextService
Example 2 (cont’d)
// Elsewhere, in a different thread, retrieve the MessageProcessor contextual proxy
// object from the store
MessageProcessor proxy = store.getIt();
// The proxy method processMessage() is invoked on
// this thread, but with the context of the servlet or
// EJB that created it.
proxy.processMessage(msg);
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.34
Program Agenda
 Overview
 Managed Objects
 Features
 Summary
 Resources
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.35
Context Propagation
 Types of container context to be propagated
– Class loading, JNDI namespace, security identity
 Configurable
 Extensible
 Supported in all 4 types of managed objects
Overview
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.36
Context Propagation
 Application context captured at
– Task submission
– ManagedThreadFactory creation
– Contextual proxy object creation
 Application context propagated to thread
– Before task execution
– During invocation of contextual proxy object methods (with the
exception of hashCode, equals, toString and all other methods
declared in Object)
Overview (cont’d)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.37
Transaction Management
 Transactions are not propagated to the threads where tasks are run
 UserTransaction from JTA is available
 Contextual proxy objects from ContextService can be run on the
same transaction context of the invoking thread
– Configurable via execution property ManagedTask.TRANSACTION
 ManagedTask.SUSPEND (default)
 ManagedTask.USE_TRANSACTION_OF_EXECUTION_THREAD
Overview
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.38
Task Events Notifications
 Task lifecycle events notifications via ManagedTaskListener
interface methods when task is:
– submitted
– not able to start or is cancelled
– about to start
– completed running, either succeeded or failed with exception
 Can be used for logging tasks progress
 Can be used for remedial actions such as resubmit a failed task
Overview
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.39
Task Events Notifications
ManagedTaskListener
 ManagedTaskListener implementations typically provided by
application component
 Listeners can be associated with tasks that are submitted to
ManagedExecutorService or
ManagedScheduledExecutorService
 Notification methods are run in unspecified context by default
– Can be made contextual with contextual proxy object for
ManagedTaskListener
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.40
Task Events Notifications
ManagedTaskListener API
 void taskSubmitted(Future<?>
future, ManagedExecutorService executor, Object
task)
 void taskStarting(Future<?>
future, ManagedExecutorService executor, Object
task)
 void taskAborted(Future<?>
future, ManagedExecutorService executor, Object
task, Throwable exception)
 void taskDone(Future<?>
future, ManagedExecutorService executor, Object
task, Throwable exception)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.41
Task Events Notifications
Registering ManagedTaskListener
// Runnable implements ManagedTask
public class TaskWithListener implements Runnable, ManagedTask {
...
public ManagedTaskListener getManagedTaskListener() {
return aManagedTaskListener;
}
}
//use ManagedExecutors utility to associate a ManagedTaskListener to a task
Runnable aTask;
ManagedTaskListener myTaskListner;
Runnable taskWithListener =
ManagedExecutors.managedTask(aTask, myTaskListener);
...
ManagedExecutorService executor = ...;
executor.submit(taskWithListener);
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.42
ManagedTask
Overview
 Any task submitted to an ManagedExecutorService or an
ManagedScheduledExecutorService can optionally implement
ManagedTask
 Provides
– Identifying information about the task
– ManagedTaskListener for lifecycle events notification
– Any additional execution properties
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.43
ManagedTask
API
 API
– Map<String, String> getExecutionProperties()
– ManagedTaskListener getManagedTaskListener()
 Execution properties
– LONGRUNNING_HINT
– IDENTITY_NAME
– TRANSACTION
 SUSPEND
 USE_TRANSACTION_OF_EXECUTION_THREAD
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.44
ManagedExecutors
Overview
 Utility class in javax.enterprise.concurrent package
 Provided by Java EE for use by application components
 Contains methods for
– Testing whether current thread is a ManageableThread that has been
marked for shutdown
– Creating a ManagedTask that connects the given Callable/Runnable
with a given ManagedTaskListener and with any given execution
properties
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.45
ManagedExecutors
API
 public static boolean isCurrentThreadShutdown()
 public static Runnable managedTask(Runnable
task, ManagedTaskListener taskListener) throws
IllegalArgumentException
 public static Runnable managedTask(Runnable
task, Map<String,String> executionProperties, ManagedTaskListener
taskListener) throws IllegalArgumentException
 public static <V> Callable<V> managedTask(Callable<V>
task, ManagedTaskListener taskListener) throws
IllegalArgumentException
 public static <V> Callable<V> managedTask(Callable<V>
task, Map<String,String> executionProperties, ManagedTaskListener
taskListener) throws IllegalArgumentException
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.46
Program Agenda
 Overview
 Managed Objects
 Features
 Summary
 Resources
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.47
Summary
 Provides asynchronous capabilities to Java EE application
components
 Allows Java SE developers simple migration path to Java EE
 Provides managed objects to applications for submitting tasks
and obtaining managed threads
 Features such as propagation of container context
 Java EE application developers now have tools to have more
advanced control of asynchronous processing
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.48
Program Agenda
 Overview
 Managed Objects
 Features
 Summary
 Resources
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.49
Resources
 Spec and API docs
– http://jcp.org/en/jsr/detail?id=236
– http://docs.oracle.com/javaee/7/api
– http://concurrency-ee-spec.java.net
 Java EE 7 SDK
– http://www.oracle.com/javaee
 Please send feedback to
– users@concurrency-ee-spec.java.net
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.50
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.51
Graphic Section Divider

Contenu connexe

Tendances

JDK 9 Java Platform Module System
JDK 9 Java Platform Module SystemJDK 9 Java Platform Module System
JDK 9 Java Platform Module SystemWolfgang Weigend
 
Burns jsf-confess-2015
Burns jsf-confess-2015Burns jsf-confess-2015
Burns jsf-confess-2015Edward Burns
 
Java EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsJava EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsMurat Yener
 
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7Bruno Borges
 
Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Hirofumi Iwasaki
 
2015 JavaOne LAD JSF 2.3 & MVC 1.0
2015 JavaOne LAD JSF 2.3 & MVC 1.02015 JavaOne LAD JSF 2.3 & MVC 1.0
2015 JavaOne LAD JSF 2.3 & MVC 1.0mnriem
 
Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!Reza Rahman
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guidePankaj Singh
 
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesMert Çalışkan
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview QuestionsSyed Shahul
 
Have You Seen Java EE Lately?
Have You Seen Java EE Lately?Have You Seen Java EE Lately?
Have You Seen Java EE Lately?Reza Rahman
 
Java EE 7 from an HTML5 Perspective, JavaLand 2015
Java EE 7 from an HTML5 Perspective, JavaLand 2015Java EE 7 from an HTML5 Perspective, JavaLand 2015
Java EE 7 from an HTML5 Perspective, JavaLand 2015Edward Burns
 
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishArun Gupta
 

Tendances (16)

JDK 9 Java Platform Module System
JDK 9 Java Platform Module SystemJDK 9 Java Platform Module System
JDK 9 Java Platform Module System
 
Burns jsf-confess-2015
Burns jsf-confess-2015Burns jsf-confess-2015
Burns jsf-confess-2015
 
JDK 10 Java Module System
JDK 10 Java Module SystemJDK 10 Java Module System
JDK 10 Java Module System
 
Java EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsJava EE Revisits GoF Design Patterns
Java EE Revisits GoF Design Patterns
 
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7
 
Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7
 
2015 JavaOne LAD JSF 2.3 & MVC 1.0
2015 JavaOne LAD JSF 2.3 & MVC 1.02015 JavaOne LAD JSF 2.3 & MVC 1.0
2015 JavaOne LAD JSF 2.3 & MVC 1.0
 
Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guide
 
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
Have You Seen Java EE Lately?
Have You Seen Java EE Lately?Have You Seen Java EE Lately?
Have You Seen Java EE Lately?
 
Hibernate3 q&a
Hibernate3 q&aHibernate3 q&a
Hibernate3 q&a
 
Java EE 7 from an HTML5 Perspective, JavaLand 2015
Java EE 7 from an HTML5 Perspective, JavaLand 2015Java EE 7 from an HTML5 Perspective, JavaLand 2015
Java EE 7 from an HTML5 Perspective, JavaLand 2015
 
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFish
 
JavaFX Enterprise
JavaFX EnterpriseJavaFX Enterprise
JavaFX Enterprise
 

Similaire à JSR 236 Concurrency Utils for EE presentation for JavaOne 2013 (CON7948)

Best Practices for JSF, Gameduell 2013
Best Practices for JSF, Gameduell 2013Best Practices for JSF, Gameduell 2013
Best Practices for JSF, Gameduell 2013Edward Burns
 
Oracle Coherence Strategy and Roadmap (OpenWorld, September 2014)
Oracle Coherence Strategy and Roadmap (OpenWorld, September 2014)Oracle Coherence Strategy and Roadmap (OpenWorld, September 2014)
Oracle Coherence Strategy and Roadmap (OpenWorld, September 2014)jeckels
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8Simon Ritter
 
Java EE7
Java EE7Java EE7
Java EE7Jay Lee
 
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)Shing Wai Chan
 
Presente e Futuro: Java EE.next()
Presente e Futuro: Java EE.next()Presente e Futuro: Java EE.next()
Presente e Futuro: Java EE.next()Bruno Borges
 
Jakarta Concurrency: Present and Future
Jakarta Concurrency: Present and FutureJakarta Concurrency: Present and Future
Jakarta Concurrency: Present and FuturePayara
 
Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.suranisaunak
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java PlatformSivakumar Thyagarajan
 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersBruno Borges
 
Framework adoption for java enterprise application development
Framework adoption for java enterprise application developmentFramework adoption for java enterprise application development
Framework adoption for java enterprise application developmentClarence Ho
 
Servlet to Spring: Internal Understanding
Servlet to Spring: Internal UnderstandingServlet to Spring: Internal Understanding
Servlet to Spring: Internal UnderstandingKnoldus Inc.
 
What's new in java 9?
What's new in java 9?What's new in java 9?
What's new in java 9?Trayan Iliev
 
MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.Miguel Araújo
 
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)Shing Wai Chan
 
Oracle ADF Architecture TV - Design - Task Flow Overview
Oracle ADF Architecture TV - Design - Task Flow OverviewOracle ADF Architecture TV - Design - Task Flow Overview
Oracle ADF Architecture TV - Design - Task Flow OverviewChris Muir
 

Similaire à JSR 236 Concurrency Utils for EE presentation for JavaOne 2013 (CON7948) (20)

Best Practices for JSF, Gameduell 2013
Best Practices for JSF, Gameduell 2013Best Practices for JSF, Gameduell 2013
Best Practices for JSF, Gameduell 2013
 
Java ee7 1hour
Java ee7 1hourJava ee7 1hour
Java ee7 1hour
 
Oracle Coherence Strategy and Roadmap (OpenWorld, September 2014)
Oracle Coherence Strategy and Roadmap (OpenWorld, September 2014)Oracle Coherence Strategy and Roadmap (OpenWorld, September 2014)
Oracle Coherence Strategy and Roadmap (OpenWorld, September 2014)
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8
 
Java EE7
Java EE7Java EE7
Java EE7
 
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
 
Presente e Futuro: Java EE.next()
Presente e Futuro: Java EE.next()Presente e Futuro: Java EE.next()
Presente e Futuro: Java EE.next()
 
Jakarta Concurrency: Present and Future
Jakarta Concurrency: Present and FutureJakarta Concurrency: Present and Future
Jakarta Concurrency: Present and Future
 
Completable future
Completable futureCompletable future
Completable future
 
Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.
 
Struts Interceptors
Struts InterceptorsStruts Interceptors
Struts Interceptors
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java Platform
 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c Developers
 
Framework adoption for java enterprise application development
Framework adoption for java enterprise application developmentFramework adoption for java enterprise application development
Framework adoption for java enterprise application development
 
Servlet to Spring: Internal Understanding
Servlet to Spring: Internal UnderstandingServlet to Spring: Internal Understanding
Servlet to Spring: Internal Understanding
 
What's new in java 9?
What's new in java 9?What's new in java 9?
What's new in java 9?
 
MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.
 
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško Vukmanović
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško VukmanovićJavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško Vukmanović
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško Vukmanović
 
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
 
Oracle ADF Architecture TV - Design - Task Flow Overview
Oracle ADF Architecture TV - Design - Task Flow OverviewOracle ADF Architecture TV - Design - Task Flow Overview
Oracle ADF Architecture TV - Design - Task Flow Overview
 

Dernier

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Dernier (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

JSR 236 Concurrency Utils for EE presentation for JavaOne 2013 (CON7948)

  • 1. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.1
  • 2. JSR 236: Introduction to Concurrency Utilities for Java EE 1.0 Anthony Lai Oracle Fred Rowe IBM
  • 3. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.3 The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • 4. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.4 Program Agenda  Overview  Managed Objects  Features  Summary  Resources
  • 5. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.5 Overview  Provide a simple and flexible standard API for application component providers to design applications using concurrency design principles  Provide a simple migration path from Java SE Concurrency Utilities (JSR-166) to the Java EE platform by providing consistency between the two platforms  Allow application component providers to easily add concurrency to existing Java EE applications  Support simple and advanced concurrency patterns without sacrificing usability Goals
  • 6. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.6 Overview  2003 – JSR 236 and JSR237 filed. CommonJ API provides context aware Work Managers and Timers to Java EE applications  2006 – CommonJ API replaced by API that extends from Java SE concurrency utilities  2008 – Merged into JSR 236  2008 – 2012 …  2012 – JSR 236 restarted  2013 – JSR 236 released and become part of Java EE 7 History
  • 7. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.7 Overview  Simple, standardized API for using concurrency from application components  Extension of Java SE Concurrency Utilities APIs (JSR-166)  Provide low-level asynchronous processing capabilities to Java EE application components in a safe, reliable, consistent manner  Manage and monitor the lifecycle of asynchronous operations Main Features
  • 8. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.8 Overview  Provides 4 types of managed objects that implement these interfaces in javax.enterprise.concurrent package: – ManagedExecutorService – ManagedScheduledExecutorService – ManagedThreadFactory – ContextService  Container context propagation  Transaction management  Task events notification Main Features
  • 9. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.9 Program Agenda  Overview  Managed Objects  Features  Summary  Resources
  • 10. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.10 Managed Objects  Managed Objects are provided by the Java EE Product Provider  Applications access managed objects by – JNDI lookup – resource injection using @Resource  Configurable  Pre-configured default managed objects are available – e.g. java:comp/DefaultManagedThreadFactory Overview
  • 11. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.11 ManagedThreadFactory  A standard way for applications to obtain a container-managed threads from Java EE Containers  Supports context propagation  Can be used with asynchronous processing API in Servlets  Can be used for creating custom executors in advanced use cases Overview
  • 12. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.12 ManagedThreadFactory  Interface extends from java.util.concurrent.ThreadFactory – Same API: Thread.newThread(Runnable) – Container context captured at ManagedThreadFactory creation will be propagated to the thread returned  Threads returned by newThread() method are required to implement the ManagableThread interface – boolean isShutdown()  Can be used with Java SE concurrency utilities APIs where ThreadFactory is needed. e.g. in java.util.concurrent.Executors API
  • 13. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.13 ManagedThreadFactory  Thread interrupted when ManagedThreadFactory shuts down  Runnable implementations should check ManagableThread.isShutdown() when interrupted – clean up if it returns true Shutdown
  • 14. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.14 ManagedThreadFactory // Create a ThreadPoolExecutor using a ManagedThreadFactory. @Resource ManagedThreadFactory tf; public ExecutorService getManagedThreadPool() { // All threads will run as part of this application component. return new ThreadPoolExecutor(5, 10, 5, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10), tf); } Example 1
  • 15. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.15 ManagedThreadFactory @WebServlet(asyncSupported=true) public class TestServlet extends HttpServlet { @Resource private ManagedThreadFactory managedThreadFactory; protected void doGet(HttpServletRequest req, HttpServletResponse res { final AsyncContext asyncContext = req.startAsync(); … Runnable runnable = new Runnable() { public void run() { … asyncContext.complete(); } }; Thread thread = managedThreadFactory.newThread(runnable); thread.start(); … } } Example 2 – Use with Asynchronous Servlet
  • 16. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.16 ManagedExecutorService  For running tasks asynchronously on threads provided by Java EE product provider – Tasks must implement either java.util.concurrent.Callable or java.lang.Runnable  Supports context propagation  Allow application developers to use familiar Java SE APIs for concurrent processing of tasks in Java EE Overview
  • 17. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.17 ManagedExecutorService  Extends from java.util.concurrent.ExecutorService – execute, submit, invokeAll, invokeAny – No new APIs  Future is returned upon task submission – Checks for the task execution status – Cancels the task – Waits and retrieves result  Lifecycle APIs disabled – throws IllegalStateException – awaitTermination, isTerminated, isShutdown, shutdown, shutd ownNow API
  • 18. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.18 ManagedExecutorService Example 1 @Resource ManagedExecutorService mes; void someMethod() { Callable<Integer> c = new Callable<>() { Integer call() { // Interact with a database...return answer. } //Submit the task and do something else. Future result = mes.submit(c); ... //Get the result when ready... int theValue = result.get(); ...
  • 19. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.19 ManagedExecutorService Example 2 – Use with Asynchronous Servlet @WebServlet(asyncSupported=true) public class TestAsyncMESServlet extends HttpServlet { @Resource private ManagedExecutorService managedExecutorService; protected void doGet(HttpServletRequest req, HttpServletResponse res { final AsyncContext asyncContext = req.startAsync(); … Runnable runnable = new Runnable() { public void run() { … asyncContext.complete(); } }; managedExecutorService.submit(runnable); … } }
  • 20. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.20 ManagedExecutorService Managed Thread Pool Executor Component Relationship
  • 21. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.21 ManagedScheduledExecutorService  For scheduling tasks to run – after a given delay – periodically – at some custom schedule  Tasks are run on threads that are provided by the Java EE container  Supports context propagation  Allows application developers to use familiar Java SE APIs for submitting scheduled tasks in Java EE Overview
  • 22. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.22 ManagedScheduledExecutorService  Extends from ManagedExecutorService  Extends from java.util.concurrent.ScheduledExecutorService – schedule, scheduleAtFixedRate, scheduleWithFixedDelay  Lifecycle APIs disabled – throws IllegalStateException – awaitTermination, isTerminated, isShutdown, shutdown, shutd ownNow  Extension API to support custom scheduling – schedule with Trigger API
  • 23. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.23 ManagedScheduledExecutorService API from ScheduledExecutorService <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); ScheduledFuture<?> scheduleAtFixedFate(Runnable command, long initialDelay, long period, TimeUnit unit); ScheduledFuture<?> scheduledWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit);
  • 24. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.24 ManagedScheduledExecutorService API for Custom Scheduling <V> ScheduledFuture<V> schedule(Callable<V> callable, Trigger trigger); ScheduledFuture<?> schedule(Runnable command, Trigger trigger);
  • 25. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.25 ManagedScheduledExecutorService Trigger  For supporting custom scheduling rules – Can be simple: single, absolute date/time – Can be complex calendar logic – Next trigger time can be calculated based on previous trigger execution date/time and result  Implemented by application developers  Submitted along with a task using the schedule method in ManagedScheduledExecutorService
  • 26. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.26 ManagedScheduledExecutorService Trigger API boolean skipRun(LastExecution lastExecutionInfo, Date scheduledRunTime) Date getNextRunTime(LastExecution lastExecutionInfo, Date taskScheduledTime)
  • 27. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.27 ManagedScheduledExecutorService Trigger Example public class SimpleFixedDateTrigger implements Trigger { private Date fireTime; public SimpleFixedDateTrigger(Date triggerDate) { fireTime = triggerDate; } public Date getNextRunTime( LastExecution lastExecutionInfo, Date taskScheduledTime) { if(taskScheduledTime.after(fireTime)) { return null; } return fireTime; } public boolean skipRun(LastExecution lastExecutionInfo, Date scheduledRunTime) { return scheduledRunTime.after(fireTime); } }
  • 28. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.28 ContextService  For creating contextual proxy objects – Application context is captured upon creation – Proxy object methods will run within the captured context at a later time  For use in advanced use cases – E.g. to propagate user identity – E.g. to request task listener notifications to be run under container context  Uses dynamic proxy mechanism in java.lang.reflect package Overview
  • 29. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.29 ContextService  Contextual proxy objects customizable through execution properties – Transaction property – Vendor specific properties, e.g. vendorA.security_token_expiration  API for returning the execution properties on the given contextual object proxy instance – Map<String,String> getExecutionProperties(Object contextualProxy) Execution Properties
  • 30. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.30 ContextService  For creating contextual proxy objects: – <T> T createContextualProxy(T instance, Class<T> intf) – Object createContextualProxy(Object instance, Class<?>... Interfaces) – <T> T createContextualProxy(T instance, Map<String,String> executionProperties, Class<T> intf) – Object createContextualProxy(Object instance, Map<String,String> executionProperties, Class<?>... Interfaces) API
  • 31. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.31 ContextService Example 1 @Resource ContextService ctxSvc; MyAppIntf proxy = ctxSvc.createContextualProxy (myAppImpl, MyAppIntf.class); // invoke at a later time, possibly in a different app // component proxy.doSomething();
  • 32. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.32 ContextService Example 2 // In application public interface MessageProcessor { public void processMessage(Message msg) … } // Within servlet or EJB method… @Resource ContextService ctxSvc; void businessMethod() { MessageProcessor msgProcessor = … // Wrap with the current context MessageProcessor proxy = ctxSvc.createContextualProxy (msgProcessor, MessageProcessor.class); // Store the contextual proxy object somewhere for running later. store.putIt(proxy); …
  • 33. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.33 ContextService Example 2 (cont’d) // Elsewhere, in a different thread, retrieve the MessageProcessor contextual proxy // object from the store MessageProcessor proxy = store.getIt(); // The proxy method processMessage() is invoked on // this thread, but with the context of the servlet or // EJB that created it. proxy.processMessage(msg);
  • 34. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.34 Program Agenda  Overview  Managed Objects  Features  Summary  Resources
  • 35. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.35 Context Propagation  Types of container context to be propagated – Class loading, JNDI namespace, security identity  Configurable  Extensible  Supported in all 4 types of managed objects Overview
  • 36. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.36 Context Propagation  Application context captured at – Task submission – ManagedThreadFactory creation – Contextual proxy object creation  Application context propagated to thread – Before task execution – During invocation of contextual proxy object methods (with the exception of hashCode, equals, toString and all other methods declared in Object) Overview (cont’d)
  • 37. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.37 Transaction Management  Transactions are not propagated to the threads where tasks are run  UserTransaction from JTA is available  Contextual proxy objects from ContextService can be run on the same transaction context of the invoking thread – Configurable via execution property ManagedTask.TRANSACTION  ManagedTask.SUSPEND (default)  ManagedTask.USE_TRANSACTION_OF_EXECUTION_THREAD Overview
  • 38. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.38 Task Events Notifications  Task lifecycle events notifications via ManagedTaskListener interface methods when task is: – submitted – not able to start or is cancelled – about to start – completed running, either succeeded or failed with exception  Can be used for logging tasks progress  Can be used for remedial actions such as resubmit a failed task Overview
  • 39. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.39 Task Events Notifications ManagedTaskListener  ManagedTaskListener implementations typically provided by application component  Listeners can be associated with tasks that are submitted to ManagedExecutorService or ManagedScheduledExecutorService  Notification methods are run in unspecified context by default – Can be made contextual with contextual proxy object for ManagedTaskListener
  • 40. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.40 Task Events Notifications ManagedTaskListener API  void taskSubmitted(Future<?> future, ManagedExecutorService executor, Object task)  void taskStarting(Future<?> future, ManagedExecutorService executor, Object task)  void taskAborted(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception)  void taskDone(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception)
  • 41. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.41 Task Events Notifications Registering ManagedTaskListener // Runnable implements ManagedTask public class TaskWithListener implements Runnable, ManagedTask { ... public ManagedTaskListener getManagedTaskListener() { return aManagedTaskListener; } } //use ManagedExecutors utility to associate a ManagedTaskListener to a task Runnable aTask; ManagedTaskListener myTaskListner; Runnable taskWithListener = ManagedExecutors.managedTask(aTask, myTaskListener); ... ManagedExecutorService executor = ...; executor.submit(taskWithListener);
  • 42. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.42 ManagedTask Overview  Any task submitted to an ManagedExecutorService or an ManagedScheduledExecutorService can optionally implement ManagedTask  Provides – Identifying information about the task – ManagedTaskListener for lifecycle events notification – Any additional execution properties
  • 43. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.43 ManagedTask API  API – Map<String, String> getExecutionProperties() – ManagedTaskListener getManagedTaskListener()  Execution properties – LONGRUNNING_HINT – IDENTITY_NAME – TRANSACTION  SUSPEND  USE_TRANSACTION_OF_EXECUTION_THREAD
  • 44. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.44 ManagedExecutors Overview  Utility class in javax.enterprise.concurrent package  Provided by Java EE for use by application components  Contains methods for – Testing whether current thread is a ManageableThread that has been marked for shutdown – Creating a ManagedTask that connects the given Callable/Runnable with a given ManagedTaskListener and with any given execution properties
  • 45. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.45 ManagedExecutors API  public static boolean isCurrentThreadShutdown()  public static Runnable managedTask(Runnable task, ManagedTaskListener taskListener) throws IllegalArgumentException  public static Runnable managedTask(Runnable task, Map<String,String> executionProperties, ManagedTaskListener taskListener) throws IllegalArgumentException  public static <V> Callable<V> managedTask(Callable<V> task, ManagedTaskListener taskListener) throws IllegalArgumentException  public static <V> Callable<V> managedTask(Callable<V> task, Map<String,String> executionProperties, ManagedTaskListener taskListener) throws IllegalArgumentException
  • 46. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.46 Program Agenda  Overview  Managed Objects  Features  Summary  Resources
  • 47. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.47 Summary  Provides asynchronous capabilities to Java EE application components  Allows Java SE developers simple migration path to Java EE  Provides managed objects to applications for submitting tasks and obtaining managed threads  Features such as propagation of container context  Java EE application developers now have tools to have more advanced control of asynchronous processing
  • 48. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.48 Program Agenda  Overview  Managed Objects  Features  Summary  Resources
  • 49. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.49 Resources  Spec and API docs – http://jcp.org/en/jsr/detail?id=236 – http://docs.oracle.com/javaee/7/api – http://concurrency-ee-spec.java.net  Java EE 7 SDK – http://www.oracle.com/javaee  Please send feedback to – users@concurrency-ee-spec.java.net
  • 50. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.50
  • 51. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.51 Graphic Section Divider

Notes de l'éditeur

  1. Welcome and Introduce speakers (takes turn)
  2. Today we will start with an overview of what JSR 236 Concurrency Utilities for Java EE is about. What its goals are and what features does it add to the Java EE platform.Then we will walk through the different types of managed objects that are defined in the spec. Then we will go through some of the feature areas that may be of interest to the developers.
  3. First of all, lets go through the goals of Concurrency Utilities as listed in the spec…
  4. Lets briefly go through the history of JSR 236. The JSR has a long history.It started way back in 2003 as 2 JSRs - JSR 236 and 237 were filed in 2003. JSR 236 defines the CommonJ Timers API for app servers while JSR 237 defines the CommonJ Work Manager API for application servers. Some of you may have used the CommonJ API before as it is supported by a few application servers.Then in 2006, after the introduction of the Concurrency Utilities API in Java SE 5, the API were rewritten to align with the API in the concurrent package in Java SE.In 2008, JSR 237 was officially withdrawn and the two JSRs were merged into JSR 236.However, no real progress were made in the next few years on the JSR. The JSR was left in an inactive state until last year when the JSR was restarted and work was resumed on the JSR. The spec was finally released this year as part of Java EE 7.
  5. What are the main features provided by the Concurrency Utilities for Java EE? On a high level, it provides- A Simple, standardized API for using concurrency from application components- Provides API for Java EE application developers that is extension of Java SE Concurrency Utilities APIs (JSR-166)- Provide low-level asynchronous processing capabilities to Java EE application components in a safe, reliable, consistent manner- Provides API for Managing and monitoring of the lifecycle of asynchronous operations
  6. More specifically, concurrency Utilities for Java EE defines 4 types of managed objects that implement the following 4 new interfaces:ManagedExecutorServiceManagedScheduledExecutorServiceManagedThreadFactory, andContextServiceThese interfaces are found in the javax.enterprise.concurrent package.The spec also defines how container context propagation and transaction management should behave for asynchronous tasks using the API. It also provides a mechanism to allow Java EE application components to receive notifications to keep track of the progress of asynchronous tasks.
  7. A managed object is an object provided by Java EE product providers that implements one of the 4 new interfaces. The managed objects are in the package javax.enterprise.concurrent.They are for use by application components. Application code can get reference to them using JNDI lookup or by using resource injection.Configurable – each application server would provide some tools, such as GUI tools or command line interface, for configuration of these managed objects.There can be multiple configured managed objects of each type, each with different configuration properties.Configuration properties not defined by the spec. It is up to each Java EE container to decide what those properties are. However, the spec requires that application server must provide a preconfigured default instance of a managed object for each of the 4 types. They can be looked up using some standard JNDI names. For example, “java:comp/DefaultManagedThreadFactory” etc.A default instance for the specified resource type is injected if “lookup” is not specified in @Resource
  8. ManagedThreadFactory provides a standard mechanism for Java EE applications to obtain a managed thread from the Java EE container. Most Java EE container discourage applications from creating plain java Threads. Those threads are not maintained by the Java EE container and may interfere with the proper operations of the container. Also, application context are not propagated to these threads. We will talk more about context propagation in a couple slides.Again, instead of reinventing the wheel, we simply extend from the ThreadFactory interface from the Java SE concurrent package, inheriting the same API for obtaining a thread. The ManagedThreadFactory is useful for obtaining threads to work with asynchronous servlets that was added to the Servlets 3.0 spec in Java EE 6. it is also useful in advanced use cases such as when the Java EE application needs to create custom executors with its own pool of threads obtained from the container.
  9. The ManagableThread interface provides a means for the application to check whether a thread created by the thread factory is in the process of shutting down.For example, a ManagedThreadFactory may be used with the utility method Executors.newCachedThreadPool from SE API
  10. ManagedExecutorService.isShutdown() throws IllegalStateException ??There is a utility method on the class ManagedExecutors.isCurrentThreadShutdown() to check whether the ManageableThread.isShutdown()
  11. public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue&lt;Runnable&gt; workQueue, ThreadFactory threadFactory)In this example, the default instance of ManagedThreadFactory will be injected and is then used to create a ThreadPoolExecutor with the desired configuration.
  12. public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue&lt;Runnable&gt; workQueue, ThreadFactory threadFactory)In this example, the default instance of ManagedThreadFactory will be injected and is then used to create a new thread on which to run the work of the async servlet. That work will run with the context of the servlet.
  13. Tasks executed by the ManagedExecutorService are run in container managed threads with the context of the application that submitted the task.
  14. It contains various forms of the execute, submit, invokeAll, and invokeAny APIs. Execute is used for submitting asynchronous tasks .Submit() methods are similar to execute(), except they return a handle, called Future, where the code can use to check for the execution status of the task, to cancel the task, or to wait for and retrieve the result of the task. InvokeAll and invokeAny methods allow submission of a collection of tasks, and provide a way to wait for and retrieve the results of either all tasks, or only the first task that completes.All of the APIs are inherited from the ExecutorService interface in the Java SE concurrent package. In fact, we did not introduce any new methods in ManagedExecutorService. This allows application developers to use APIs from Java SE concurrency package that they are already familiar with in their Java EE applications. The lifecycle of a ManagedExecutorService is managed by an application server. All lifecycle operations (like shutdown()) on the ManagedExecutorService interface will throw a java.lang.IllegalStateException exception.
  15. In this example, the default instance of ManagedExecutorService will be injected and is then used to submit a task which will execute with the context of the application. The Future returned by submit() may be used to determine the status of the task and to access the results.
  16. In this example, the default instance of ManagedExecutorService will be injected and is then used to submit an async servlet task which will execute with the context of the application. The Future returned by submit() may be used to determine the status of the task and to access the results.
  17. A ManagedExecutorService instance is intended to be used by multiple components and applications. When the executor runs a task, the context of the thread is changed to match the component instance that submitted the task. The context is then restored when the task is complete.In the figure, a single ManagedExecutorService instance is used to run tasks (in blue) from multiple application components (each denoted in a different color). Each task, when submitted to the ManagedExecutorService automatically retains the context of the submitting component and it becomes a Contextual Task. When the ManagedExecutorService runs the task, the task would be run in the context of the submitting component (as noted by different colored boxes in the figure).ManagedExecutorService instances may be terminated or suspended by the application server when applications or components are stopped or the application server itself is shutting down.
  18. The next interface that is provided by the managed objects is ManagedScheduledExecutorService.It is used for scheduling tasks to run after a given delay, to run periodically, or at some custom schedule that is controlled programmatically. Similar to ManagedExecutorService, these tasks are also run on threads that are provided by the Java EE container.
  19. The ManagedScheduledExecutorService implements both ManagedExecutorService and ScheduledExecutorService APIs.
  20. The first and second schedule() methods provide a means to execute a task once after a fixed delay.The scheduleAtFixedFate() method provides a means to schedule a task to run periodically either at specified period or at a specified delay after completion of the task
  21. These schedule() methods provides a means to execute a task with a custom schedule as specified by the Trigger.
  22. Instances of Triggers are not contextualized by default, but may be contextualized by using the ContextService.
  23. skipRun: Return true if this run instance should be skipped.This is useful if the task shouldn&apos;t run because it is late or if the task is paused or suspended.Once this task is skipped, the state of it&apos;s Future&apos;s result will throw a SkippedException. Unchecked exceptions will be wrapped in a SkippedException.-------------------------getNextRunTime: Retrieve the next time that the task should run after.
  24. This is an example of a trigger which executes a task at a specific time.The getNextRunTime() method calculates whether the specified time for the execution has already passed, and if so, will return null indicating that, otherwsie, it will return the specifc time at which to execute the task.The skipRun() method similarly simply calculates whether it is already past the time at which the task was scheduled to run. The LastExecution will either be null indicating the task hasn’t run or can be used to retrieve either the results or other info about the task.
  25. Can be used to create dynamic proxy objects (as defined by java.lang.reflect.Proxy)
  26. The only execution properties required by the spec are the IDENTITY_NAME, LONGRUNNING_HINT and TRANSACTION
  27. More details on context propagation. It is important for tasks and methods from contextual proxy objects to be run under the same context supplied for the application by the container which is the same as that in the application where they are submitted from or created.The types of container context listed in the spec includes classloading, JNDI namespace, and security identity.Note that transactional context is not one of them.Configurable – Each MO can be configured to propagate different types of container context by an administrator. Extensible - The types of container context do not need to be restricted to the 3 types listed in this slides. The concurrency EE spec allows Java EE containers to support propagation of additional context types. However, the 3 types of container context listed here are required to be supported and propagated in the default managed objects provided by all Java EE containers.
  28. When does context propagation happen?When using ManagedExecutorService or ManagedScheduledExecutorService to submit a task to be run asynchronously on a container managed thread, the Java EE container would capture such context information at the time of task submission, and reapply the context information on the container managed thread that is used for running the task just before the task is run. The result is that the task, even though it is most likely being run on a thread that is different from the thread where it is submitted from, would be able to load classes from the application that submitted the task, to perform JNDI lookup as if it is running in the same application as the one that submit the task, and to run under the same user identity that was logged in to the application when the task was submitted.In the case of ManagedThreadFactory, the container context would be captured when its newThread method is called to retrieve a managed thread. When the managed thread is started, the captured context would be applied to the thread before calling the run() method of the Runnable task that is passed into the newThread method.For ContextService, the container context are captured when a contextual proxy object is created, ie, when the createContextualProxy API is called. Later, when the proxy method is invoked, the captured context is imposed onto the thread even if the method is invoked on a thread that has a different container context. The context of that application component will be restored after the proxy method is completed.
  29. The next feature that we would like to talk about is how transaction management is supported in the managed objects.When a task is run on a different thread from the one that submitted the task, as in the case in ManagedExecutorService, and ManagedSchduledExecutorService, or when a thread is obtained from ManagedThreadFactory, transaction is not propagated from the thread where the task is submitted or where the thread is obtained, to the managed thread where the task is run. However, transaction demarcation is still possible from within the task with the use of the UserTransaction interface from the Java Transaction API specification, or JTA. Java EE container are required to provide UserTransaction to the tasks so a task implementation can begin, commit, or rollback a transaction using the UserTransaction if it wanted to.For contextual proxy objects, the spec provides two choices for the application developers regarding transaction management. One option is to run the proxy method under the same transaction as the thread where the proxy method is invoked from. For example, if the proxy method is invoked from an application component with a transaction already started, any resources used by the contextual proxy object method will be enlisted into the same transaction, and will be committed or rolled back together along with the resources enlisted by the application component. (note: A UserTransaction will only be available if it is also available in the execution thread (for example, when the proxy method is invoked from a Servlet or Bean Managed Transaction EJB).Another option to run the contextual proxy object method under a different transaction. In this case, the transaction of the application component will be suspended, and the proxy method can use UserTransaction for transaction demarcation, and any work done within the proxy method will be committed or rolled back before the method returns. At the end of the method call, the transaction of the invoking application component will be restored. The choice of option can be specified programmatically when the contextual proxy object is created.
  30. Spec supports notifications of lifecycle events for tasks submitted to MES or MSES with the use of MTL interfaceTask lifecycle events:- SubmittedAborted such as unable to start, perhaps disallowed by application server due to server resource constraint policy, or perhaps the application component that submitted the task has endedOr Cancelled – cancelled by applicationFor logging and monitoring of tasks progressRemedial actions – for example, a task that tries to retrieve some data from a remote service has timed out and failed. Upon getting a notification that the task has failed, the application can resubmit the task or perhaps send an email to the administrator about the failure.
  31. Unspecified context by default for performance reasons - we don’t want application servers to incur the cost of setting up container context before calling the listener methods if it is not needed by the methods.
  32. Note that each of the methods are passed with A Future object that was returned when the task was submitted. This can be used for checking the execution status of the task, whether it has been cancelled or completed. The Future can also be used for cancelling the taskAn executor which the task was submitted to. This can be used for resubmitting the task if necessaryThe original task that was submitted. Again this can be useful when the an application wants to resubmit the taskIn the taskAborted and taskDone methods, an exception object is also passed in to the methods to provide details about what has caused the task to be aborted or what caused the task to fail. For example, an instance of CancellationException would be passed if the task was cancelled by the application.
  33. Examples showing how to associate a ManagedTaskListener with a Runnable task.One way is to have the task implement an interface called ManagedTask, in addition to implementing Runnable or Callable.The spec also provide a helper API to return a task that associates a ManagedTaskListener to a given task. Then you would submit the task that is returned by that helper method to the executor. This is useful for example, when the task implementation comes from a different library than the ManagedTaskListener.
  34. Any task submitted to MES or MSES can optionally implement the ManagedTask interface.It allows applications to provide identifying information about a task, to provide an instance of ManagedTaskListener to get notification of lifecycle events of the task as we just discussed, or to provide additional execution properties.
  35. Contains 2 APIs. One for returning the ManagedTaskListener, the other for returning the execution properties associated with the task.Execution properties allow application to provide additional information or hints to the application server about the task that is being submitted.Standard execution properties defined in the spec are located in the ManagedTask interface, which includes:LONGRUNNING_HINT – A hint telling whether the task could take a long time to complete. Java™ EE Containers may make use of this hint value to decide how to allocate thread resource for running this task.IDENTITY_NAME – provides a name or ID for the task so that the task can be easily identifiable through any management or monitoring utilities provided by the application serverTRANSACTION – tells the Java™ EE Container under which transaction should the proxy methods of a contextual proxy object be executed in, as we have discussed a few slides earlier.
  36. isCurrentThreadShutdown() - Utility method for checking the isShutdown() value of the current thread if it is a ManageableThread created from ManagedThreadFactory.newThread() .
  37. There are only 5 APIs in this utility class.First one for detecting whether the current thread is marked for shutdownThe remaining 4 are for associating a given Runnable or Callable with a ManangedTaskListener and execution properties. The first 2 of these methods are for use when the original task is a Runnable, one of which only associates a ManagedTaskListener to the Runnable whereas the other one also associates a Map containing execution properties to the Runnable task.The other 2 methods are similar but for use when the original task is a Callable.
  38. Container context – propagation of context supplied for the application by the container so that tasks or proxy methods will be run under the proper container context.
  39. JIRA issues from project website.Errata can be found thereNew features request welcome for next release – go to project website and file jira issue.Emphasize feedback email