SlideShare a Scribd company logo
© 2015 IBM Corporation
AAI-2236
Using the New Java Concurrency Utilities
with IBM WebSphere
Kevin Sutter, STSM
WebSphere Java EE Architect
Agenda
• Introduction
• Managed services
• Additional APIs
• Additional Resources
1
Introduction
2
2003 2006 2008 2012 2013
JSR 236
released as part
of Java EE 7
JSR237 is
merged into
JSR236
JSR236 (Timers)
and JSR237 (Work
Managers) filed
CommonJ API
replaced with
extension of Java SE
concurrency API
JSR 236
restarted
JSR Timeline
Introduction
Goals
• Provide easy-to-use support to developers for both simple and
advanced concurrency patterns
• Provide a path to migrate standalone apps using Java SE
Concurrency Utilities (JSR-166) to the Java EE platform with a
consistent API
• Provide an easy-to-understand API for developers to create
applications using concurrency design principles
• Make it easy to add concurrency to existing Java EE
applications
3
Introduction
• Extension of the Java SE Concurrency Utilities API
• Addresses long standing tenant of EE app servers that well-
behaved applications should not create threads
• WebSphere (like other application servers) provided other
mechanisms for creating and managing threads, such as
Asynchronous Beans, CommonJ Timer and Work Manager.
• Asynchronous task lifecycle management, monitoring and
notification
• Flexible propagation of common Java EE contexts to tasks
4
Available 4Q2014 via Liberty Repository!
Agenda
• Introduction
• Managed services
• Additional APIs
• Summary
• Additional Resources
5
Services
Overview
• JSR 236 defines four services to be provided by an application
server
• ManagedExecutorService
• ManagedScheduledExecutorService
• ManagedThreadFactory
• ContextService
• Services are accessed by application via:
• resource injection using @Resource
• JNDI lookup
• default instances
• Configured through vendor-defined properties
6
Services
ManagedExecutorService overview
• Provides a familiar API for concurrent processing of tasks in
Java EE
• Extends java.util.concurrent.ExecutorService of
Java SE concurrency API
• Allow execution of asynchronous tasks on server managed
threads
• Tasks must implement either:
– java.lang.Runnable
– java.util.concurrent.Callable
7
Services
ManagedExecutorService API
• Supports Java EE context propagation including JNDI naming,
classloader, and security contexts
• Not transactional contexts
• Because the service is managed by the server, calling any of
the lifecycle API methods results in IllegalStateException
• Like Java SE, task(s) submission returns one or more
Future(s). These are used to:
• check for task execution status
• wait for and retrieve task result
• cancel task
8
Services
ManagedExecutorService Example
@WebServlet(asyncSupported=true)
public class MyServlet extends HttpServlet {
@Resource ManagedExecutorService managedExecutorService;
protected void doGet(HttpServletRequest request,
HttpServletResponse response {
final AsyncContext asyncContext = request.startAsync();
…
Runnable myTask = new Runnable() {
public void run() {
asyncContext.complete();
}
};
…
Future future = managedExecutorService.submit(myTask);
}
9
Services
ManagedScheduledExecutorService overview
• Provides a familiar API for scheduling asynchronous tasks in
Java EE
• Supports Java EE context propagation including JNDI naming,
classloader, and security contexts
• Not transactional contexts
• Used for scheduling tasks to run:
• periodically
• after specified delay
• at some custom schedule
10
Services
ManagedScheduledExecutorService API
• Extends both ManagedExecutorService and
java.util.concurrent.ScheduledExecutorService
interfaces
• Like ManagedExecutorService, calling any of the lifecycle
API methods results in IllegalStateException
• In addition to schedule methods inherited from Java SE API,
adds methods to support custom scheduling
• schedule with Trigger interface
11
Services
ManagedScheduledExecutorService Trigger API
• Interface implemented by application developer to support
flexible, custom scheduling
• Scheduling rules may be:
• simple: a single, absolute date/time
• complex: calendar logic
• Trigger is submitted along with a task using a schedule
method in ManagedScheduledExecutorService
12
Services
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);
}
}
13
Services
ManagedThreadFactory overview
• Provides the means for Java EE applications to obtain
container-managed threads
• Supports Java EE context propagation including JNDI naming,
classloader, and security contexts
• Not transactional contexts
14
Services
ManagedThreadFactory API
• Extends java.util.concurrent.ThreadFactory
• Same API: Thread.newThread(Runnable)
• Supports Java EE context propagation including JNDI naming,
classloader, and security contexts
• Not transactional contexts
• Threads from factory are:
• contextualized with container context
• required to implement the ManagableThread interface
15
Services
ManagedThreadFactory Example
// Create a ThreadPoolExecutor using a ManagedThreadFactory.
@Resource ManagedThreadFactory threadFactory;
public ExecutorService getManagedThreadPool() {
// All threads will be contextualized with the context
// of the creating application component.
return new ThreadPoolExecutor(5, 10, 5, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(10), threadFactory);
}
16
Services
ContextService overview
• Creates dynamic proxy objects
• objects are contextualized with container context upon creation
• object methods execute with that captured context
• Used by the other services to contextualize task and threads
• May be used directly for advanced use cases:
• request contextualization of Trigger methods
• request contextualization of task listener notification methods
• propagate custom contexts
• Execution properties control how contextualization occurs
17
Services
ContextService API
• Methods to create 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)
18
Services
ContextService Example
public class MyRunnable implements Runnable {
public void run() {
System.out.println("MyRunnable.run with Java EE Context");
}
}
@Resource ThreadFactory threadFactory;
@Resource ContextService ctxService;
MyRunnable myRunnableInstance = new MyRunnable();
Runnable rProxy =ctxService.createContextualProxy(
myRunnableInstance, Runnable.class);
ExecutorService exSvc = Executors.newThreadPool(10, threadFactory);
Future future = exSvc.submit(rProxy);
19
Agenda
• Introduction
• Managed services
• Additional APIs
• Additional Resources
20
Additional APIs
Transaction Management
• Transactions are not propagated to the threads on which tasks
are run
• Application may obtain a UserTransaction from JTA
• Contextual proxy objects can run in the transaction context of
the invoking thread, controlled by the execution property
ManagedTask.TRANSACTION
• default is ManagedTask.SUSPEND
• ManagedTask.USE_TRANSACTION_OF_EXECUTION_THREAD
21
Additional APIs
ManagedTaskListener
• Tasks events are emitted to listeners via
ManagedTaskListener methods when tasks are:
• submitted
• unable to start or cancelled
• starting
• completed, either successfully or with exceptions
• Useful for:
• monitoring task progress
• resubmitting failed tasks
• ManagedTaskListener methods execute with unspecified
context by default
22
Additional APIs
ManagedTask
• Any task can optionally implement ManagedTask interface
which provides:
• ManagedTaskListener for lifecycle events notification
• task identification
• any desired execution properties
• Other standard execution ManagedTask properties
• IDENTITY_NAME – used to provide a task name
• LONGRUNNING_HINT – hint of task length
• TRANSACTION – controls transaction participation
– SUSPEND
– USE_TRANSACTION_OF_EXECUTION_THREAD
23
Additional APIs
ManagedExecutors
• Similar to Executors utility class of Java SE concurrency
package, contain methods for:
• Creating a ManagedTask capable of receiving notifications via
the specified ManagedTaskListener and with any specified
execution properties
• Testing whether current thread is a ManageableThread that has
been marked for shutdown
24
Agenda
• Introduction
• Managed services
• Additional APIs
• Additional Resources
25
Additional Resources
• JSR236 specification and API docs
• http://jcp.org/en/jsr/detail?id=236
• JSR236 forum
• http://concurrency-ee-spec.java.net
• Java EE 7 API docs
• http://docs.oracle.com/javaee/7/api
26
Sampling of Related Sessions…
• AAI-1713A: Introduction to Java EE 7
• Monday, 2-3pm, Mandalay Bay, Reef Ballroom E
• AAI-1641A: Introduction to Web Sockets
• Monday, 5-6pm, Mandalay Bay, Reef Ballroom E
• AAI-1313A: Agile Development Using Java EE 7 with WebSphere Liberty Profile
(LAB)
• Tuesday, 8-10am, Mandalay Bay, South Seas Ballroom D
• AAI-2236A: Using the New Java Concurrency Utilities with IBM WebSphere
• Tuesday, 2-3pm, Mandalay Bay, Reef Ballroom D
• AAI-2235A: OpenJPA and EclipseLink Usage Scenarios Explained
• Wednesday, 5:30-6:30pm, Mandalay Bay, Surf Ballroom A
• AAI-1610A: Configuring IBM WebSphere Application Server for Enterprise
Messaging Needs
• Wednesday, 5:30-6:30pm, Mandalay Bay, Surf Ballroom E
• AAI-3085A: Don’t Wait! Develop Responsive Applications with Java EE7 Instead
• Thursday, 10:30-11:30am, Mandalay Bay, Lagoon L
27
Questions?
28
Notices and Disclaimers
Copyright © 2015 by International Business Machines Corporation (IBM). No part of this document may be reproduced or
transmitted in any form without written permission from IBM.
U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM.
Information in these presentations (including information relating to products that have not yet been announced by IBM) has been
reviewed for accuracy as of the date of initial publication and could include unintentional technical or typographical errors. IBM
shall have no responsibility to update this information. THIS DOCUMENT IS DISTRIBUTED "AS IS" WITHOUT ANY WARRANTY,
EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL IBM BE LIABLE FOR ANY DAMAGE ARISING FROM THE USE OF
THIS INFORMATION, INCLUDING BUT NOT LIMITED TO, LOSS OF DATA, BUSINESS INTERRUPTION, LOSS OF PROFIT
OR LOSS OF OPPORTUNITY. IBM products and services are warranted according to the terms and conditions of the
agreements under which they are provided.
Any statements regarding IBM's future direction, intent or product plans are subject to change or withdrawal without
notice.
Performance data contained herein was generally obtained in a controlled, isolated environments. Customer examples are
presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual
performance, cost, savings or other results in other operating environments may vary.
References in this document to IBM products, programs, or services does not imply that IBM intends to make such products,
programs or services available in all countries in which IBM operates or does business.
Workshops, sessions and associated materials may have been prepared by independent session speakers, and do not
necessarily reflect the views of IBM. All materials and discussions are provided for informational purposes only, and are neither
intended to, nor shall constitute legal or other guidance or advice to any individual participant or their specific situation.
It is the customer’s responsibility to insure its own compliance with legal requirements and to obtain advice of competent legal
counsel as to the identification and interpretation of any relevant laws and regulatory requirements that may affect the customer’s
business and any actions the customer may need to take to comply with such laws. IBM does not provide legal advice or
represent or warrant that its services or products will ensure that the customer is in compliance with any law.
Notices and Disclaimers (con’t)
Information concerning non-IBM products was obtained from the suppliers of those products, their published
announcements or other publicly available sources. IBM has not tested those products in connection with this
publication and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM
products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products.
IBM does not warrant the quality of any third-party products, or the ability of any such third-party products to
interoperate with IBM’s products. IBM EXPRESSLY DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED,
INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE.
The provision of the information contained herein is not intended to, and does not, grant any right or license under any
IBM patents, copyrights, trademarks or other intellectual property right.
• IBM, the IBM logo, ibm.com, Bluemix, Blueworks Live, CICS, Clearcase, DOORS®, Enterprise Document
Management System™, Global Business Services ®, Global Technology Services ®, Information on Demand,
ILOG, Maximo®, MQIntegrator®, MQSeries®, Netcool®, OMEGAMON, OpenPower, PureAnalytics™,
PureApplication®, pureCluster™, PureCoverage®, PureData®, PureExperience®, PureFlex®, pureQuery®,
pureScale®, PureSystems®, QRadar®, Rational®, Rhapsody®, SoDA, SPSS, StoredIQ, Tivoli®, Trusteer®,
urban{code}®, Watson, WebSphere®, Worklight®, X-Force® and System z® Z/OS, are trademarks of
International Business Machines Corporation, registered in many jurisdictions worldwide. Other product and
service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on
the Web at "Copyright and trademark information" at: www.ibm.com/legal/copytrade.shtml.
Thank You
Your Feedback is
Important!
Access the InterConnect 2015
Conference CONNECT Attendee
Portal to complete your session
surveys from your smartphone,
laptop or conference kiosk.
Ad

Recommended

PDF
Enterprise Persistence in OSGi - Mike Keith, Oracle
mfrancis
 
PDF
Haj 4308-open jpa, eclipselink, and the migration toolkit
Kevin Sutter
 
PPT
Servlet programming
Mallikarjuna G D
 
PPTX
Building 12-factor Cloud Native Microservices
Jakarta_EE
 
PPTX
Amis conference soa deployment. the dirty tricks using bamboo, nexus and xl ...
Getting value from IoT, Integration and Data Analytics
 
PPTX
WebLogic and GraalVM
Michel Schildmeijer
 
PDF
Contributors Guide to the Jakarta EE 10 Galaxy
Jakarta_EE
 
DOC
Oracle soa 10g to 11g migration
Krishna R
 
PPTX
Oracle soa online training
mindmajixtrainings
 
PPTX
Angularj2.0
Mallikarjuna G D
 
PDF
Upgrading Oracle SOA Suite 10g to 11g (whitepaper)
Revelation Technologies
 
PPT
Servlet programming
Mallikarjuna G D
 
PPT
Java servlet life cycle - methods ppt
kamal kotecha
 
PDF
Connector Architecture 1.6 - Tech-days 2010, Hyderabad.
Jagadish Prasath
 
PDF
Testing Web Apps with Spring Framework 3.2
Rossen Stoyanchev
 
PPTX
Angular 2.0
Mallikarjuna G D
 
PPTX
The Eclipse Transformer Project
Jakarta_EE
 
PDF
WebLogic for DBAs
Simon Haslam
 
PDF
NLOUG 2017- Oracle WebCenter Portal 12c Performance
Daniel Merchán García
 
PDF
Servlets lecture1
Tata Consultancy Services
 
PDF
.NET Core, ASP.NET Core Course, Session 17
Amin Mesbahi
 
PDF
Wt unit 3 server side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
NLOUG 2018 - Future of JSF and ADF
Daniel Merchán García
 
PPTX
Core web application development
Bahaa Farouk
 
PPTX
Copper: A high performance workflow engine
dmoebius
 
PPTX
ASP.NET MVC 4 Request Pipeline Internals
Lukasz Lysik
 
PPTX
Voyage au Royaume de Serendip / Ignite Paris
Henri Kaufman
 
PPT
Cercle marketing Direct Lyon
Henri Kaufman
 
PPT
Debrief Web2.0 San Francisco 2009
Henri Kaufman
 

More Related Content

What's hot (19)

DOC
Oracle soa 10g to 11g migration
Krishna R
 
PPTX
Oracle soa online training
mindmajixtrainings
 
PPTX
Angularj2.0
Mallikarjuna G D
 
PDF
Upgrading Oracle SOA Suite 10g to 11g (whitepaper)
Revelation Technologies
 
PPT
Servlet programming
Mallikarjuna G D
 
PPT
Java servlet life cycle - methods ppt
kamal kotecha
 
PDF
Connector Architecture 1.6 - Tech-days 2010, Hyderabad.
Jagadish Prasath
 
PDF
Testing Web Apps with Spring Framework 3.2
Rossen Stoyanchev
 
PPTX
Angular 2.0
Mallikarjuna G D
 
PPTX
The Eclipse Transformer Project
Jakarta_EE
 
PDF
WebLogic for DBAs
Simon Haslam
 
PDF
NLOUG 2017- Oracle WebCenter Portal 12c Performance
Daniel Merchán García
 
PDF
Servlets lecture1
Tata Consultancy Services
 
PDF
.NET Core, ASP.NET Core Course, Session 17
Amin Mesbahi
 
PDF
Wt unit 3 server side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
NLOUG 2018 - Future of JSF and ADF
Daniel Merchán García
 
PPTX
Core web application development
Bahaa Farouk
 
PPTX
Copper: A high performance workflow engine
dmoebius
 
PPTX
ASP.NET MVC 4 Request Pipeline Internals
Lukasz Lysik
 
Oracle soa 10g to 11g migration
Krishna R
 
Oracle soa online training
mindmajixtrainings
 
Angularj2.0
Mallikarjuna G D
 
Upgrading Oracle SOA Suite 10g to 11g (whitepaper)
Revelation Technologies
 
Servlet programming
Mallikarjuna G D
 
Java servlet life cycle - methods ppt
kamal kotecha
 
Connector Architecture 1.6 - Tech-days 2010, Hyderabad.
Jagadish Prasath
 
Testing Web Apps with Spring Framework 3.2
Rossen Stoyanchev
 
Angular 2.0
Mallikarjuna G D
 
The Eclipse Transformer Project
Jakarta_EE
 
WebLogic for DBAs
Simon Haslam
 
NLOUG 2017- Oracle WebCenter Portal 12c Performance
Daniel Merchán García
 
Servlets lecture1
Tata Consultancy Services
 
.NET Core, ASP.NET Core Course, Session 17
Amin Mesbahi
 
NLOUG 2018 - Future of JSF and ADF
Daniel Merchán García
 
Core web application development
Bahaa Farouk
 
Copper: A high performance workflow engine
dmoebius
 
ASP.NET MVC 4 Request Pipeline Internals
Lukasz Lysik
 

Viewers also liked (20)

PPTX
Voyage au Royaume de Serendip / Ignite Paris
Henri Kaufman
 
PPT
Cercle marketing Direct Lyon
Henri Kaufman
 
PPT
Debrief Web2.0 San Francisco 2009
Henri Kaufman
 
PPTX
Campbell : une expérience de Neuro Marketing
Henri Kaufman
 
PPT
Wireframe -teachers
Julie Wilson
 
PDF
AAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
Kevin Sutter
 
PPT
Inceneritori…valutazione dell’impatto sulla salute umana
ISEA ODV
 
PPTX
Expropiación de tierras en san pedro y san
Gabyy OrTeggaa
 
PPTX
FEED BACK
Luciana Tamas
 
PPT
Inside government presentation
AbbyDCLG
 
PPTX
Adult education training final basic
valejohn
 
PPS
Sonrisas. Humor de Morgan
Salvador Hernández Carballo
 
PDF
A comparative study of Diathermy Vs Scalpel skin incision in abdominal surgeries
iosrjce
 
PPTX
Kashmir & agra pure silk capets
The Gallery - Exclusive
 
DOCX
Questions 1 2
jamieboon
 
PDF
Fr87wic o
BhbyfUfdhbkjdf
 
PPTX
Outfits
nualamckevitt
 
PPTX
Expropiación de tierras en san pedro y san
Gabyy OrTeggaa
 
PPT
Marketing in an age of media disruption
John Andrews
 
PDF
Secretos de leonardo habilidades personales
Rociocomp
 
Voyage au Royaume de Serendip / Ignite Paris
Henri Kaufman
 
Cercle marketing Direct Lyon
Henri Kaufman
 
Debrief Web2.0 San Francisco 2009
Henri Kaufman
 
Campbell : une expérience de Neuro Marketing
Henri Kaufman
 
Wireframe -teachers
Julie Wilson
 
AAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
Kevin Sutter
 
Inceneritori…valutazione dell’impatto sulla salute umana
ISEA ODV
 
Expropiación de tierras en san pedro y san
Gabyy OrTeggaa
 
FEED BACK
Luciana Tamas
 
Inside government presentation
AbbyDCLG
 
Adult education training final basic
valejohn
 
Sonrisas. Humor de Morgan
Salvador Hernández Carballo
 
A comparative study of Diathermy Vs Scalpel skin incision in abdominal surgeries
iosrjce
 
Kashmir & agra pure silk capets
The Gallery - Exclusive
 
Questions 1 2
jamieboon
 
Fr87wic o
BhbyfUfdhbkjdf
 
Outfits
nualamckevitt
 
Expropiación de tierras en san pedro y san
Gabyy OrTeggaa
 
Marketing in an age of media disruption
John Andrews
 
Secretos de leonardo habilidades personales
Rociocomp
 
Ad

Similar to AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere (20)

PPTX
JSR 236 Concurrency Utils for EE presentation for JavaOne 2013 (CON7948)
Fred Rowe
 
PDF
Java EE 7 Recipes for Concurrency - JavaOne 2014
Josh Juneau
 
PPTX
Jakarta Concurrency: Present and Future
Payara
 
PDF
Presente e Futuro: Java EE.next()
Bruno Borges
 
PDF
OTN Tour 2013: What's new in java EE 7
Bruno Borges
 
PDF
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
Kevin Sutter
 
PDF
AAI-1713 Introduction to Java EE 7
WASdev Community
 
PDF
AAI 1713-Introduction to Java EE 7
Kevin Sutter
 
PPT
Java EE7 in action
Ankara JUG
 
ODP
JUDCON India 2014 Java EE 7 talk
Vijay Nair
 
PDF
Java EE 7, what's in it for me?
Alex Soto
 
PPT
GlassFish BOF
glassfish
 
PPTX
Java ee7 1hour
Frank Rodriguez
 
PDF
Haj 4328-java ee 7 overview
Kevin Sutter
 
PDF
50 features of Java EE 7 in 50 minutes at JavaZone 2014
Arun Gupta
 
PPTX
Getting Started with Java EE 7
Arun Gupta
 
PDF
50 features of Java EE 7 in 50 minutes at Geecon 2014
Arun Gupta
 
PPT
Don't Wait! Develop responsive applications with Java EE7 instead
Erin Schnabel
 
PDF
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
Arun Gupta
 
PDF
Fifty New Features of Java EE 7 in Fifty Minutes
Arun Gupta
 
JSR 236 Concurrency Utils for EE presentation for JavaOne 2013 (CON7948)
Fred Rowe
 
Java EE 7 Recipes for Concurrency - JavaOne 2014
Josh Juneau
 
Jakarta Concurrency: Present and Future
Payara
 
Presente e Futuro: Java EE.next()
Bruno Borges
 
OTN Tour 2013: What's new in java EE 7
Bruno Borges
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
Kevin Sutter
 
AAI-1713 Introduction to Java EE 7
WASdev Community
 
AAI 1713-Introduction to Java EE 7
Kevin Sutter
 
Java EE7 in action
Ankara JUG
 
JUDCON India 2014 Java EE 7 talk
Vijay Nair
 
Java EE 7, what's in it for me?
Alex Soto
 
GlassFish BOF
glassfish
 
Java ee7 1hour
Frank Rodriguez
 
Haj 4328-java ee 7 overview
Kevin Sutter
 
50 features of Java EE 7 in 50 minutes at JavaZone 2014
Arun Gupta
 
Getting Started with Java EE 7
Arun Gupta
 
50 features of Java EE 7 in 50 minutes at Geecon 2014
Arun Gupta
 
Don't Wait! Develop responsive applications with Java EE7 instead
Erin Schnabel
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
Arun Gupta
 
Fifty New Features of Java EE 7 in Fifty Minutes
Arun Gupta
 
Ad

More from Kevin Sutter (7)

PDF
DevNexus 2019: MicroProfile and Jakarta EE - What's Next?
Kevin Sutter
 
PDF
Implementing Microservices with Jakarta EE and MicroProfile
Kevin Sutter
 
PDF
Bmc 4286-micro profile-a programming model for microservices-based applications
Kevin Sutter
 
PDF
Ham 4393-micro profile, java ee, and the application server
Kevin Sutter
 
PDF
Haj 4344-java se 9 and the application server-1
Kevin Sutter
 
PDF
Bas 5676-java ee 8 introduction
Kevin Sutter
 
PDF
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)
Kevin Sutter
 
DevNexus 2019: MicroProfile and Jakarta EE - What's Next?
Kevin Sutter
 
Implementing Microservices with Jakarta EE and MicroProfile
Kevin Sutter
 
Bmc 4286-micro profile-a programming model for microservices-based applications
Kevin Sutter
 
Ham 4393-micro profile, java ee, and the application server
Kevin Sutter
 
Haj 4344-java se 9 and the application server-1
Kevin Sutter
 
Bas 5676-java ee 8 introduction
Kevin Sutter
 
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)
Kevin Sutter
 

Recently uploaded (20)

PDF
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
PDF
A Guide to Telemedicine Software Development.pdf
Olivero Bozzelli
 
PPTX
arctitecture application system design os dsa
za241967
 
PPTX
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
PDF
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
PDF
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
PDF
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
PDF
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
mary rojas
 
PPTX
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
 
PDF
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
 
PDF
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
PPTX
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
PPTX
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
PPTX
declaration of Variables and constants.pptx
meemee7378
 
PDF
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
PPT
Complete Guideliness to Build an Effective Maintenance Plan.ppt
QualityzeInc1
 
PDF
Which Hiring Management Tools Offer the Best ROI?
HireME
 
PDF
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
PDF
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
PDF
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
A Guide to Telemedicine Software Development.pdf
Olivero Bozzelli
 
arctitecture application system design os dsa
za241967
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
mary rojas
 
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
 
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
declaration of Variables and constants.pptx
meemee7378
 
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
Complete Guideliness to Build an Effective Maintenance Plan.ppt
QualityzeInc1
 
Which Hiring Management Tools Offer the Best ROI?
HireME
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 

AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere

  • 1. © 2015 IBM Corporation AAI-2236 Using the New Java Concurrency Utilities with IBM WebSphere Kevin Sutter, STSM WebSphere Java EE Architect
  • 2. Agenda • Introduction • Managed services • Additional APIs • Additional Resources 1
  • 3. Introduction 2 2003 2006 2008 2012 2013 JSR 236 released as part of Java EE 7 JSR237 is merged into JSR236 JSR236 (Timers) and JSR237 (Work Managers) filed CommonJ API replaced with extension of Java SE concurrency API JSR 236 restarted JSR Timeline
  • 4. Introduction Goals • Provide easy-to-use support to developers for both simple and advanced concurrency patterns • Provide a path to migrate standalone apps using Java SE Concurrency Utilities (JSR-166) to the Java EE platform with a consistent API • Provide an easy-to-understand API for developers to create applications using concurrency design principles • Make it easy to add concurrency to existing Java EE applications 3
  • 5. Introduction • Extension of the Java SE Concurrency Utilities API • Addresses long standing tenant of EE app servers that well- behaved applications should not create threads • WebSphere (like other application servers) provided other mechanisms for creating and managing threads, such as Asynchronous Beans, CommonJ Timer and Work Manager. • Asynchronous task lifecycle management, monitoring and notification • Flexible propagation of common Java EE contexts to tasks 4 Available 4Q2014 via Liberty Repository!
  • 6. Agenda • Introduction • Managed services • Additional APIs • Summary • Additional Resources 5
  • 7. Services Overview • JSR 236 defines four services to be provided by an application server • ManagedExecutorService • ManagedScheduledExecutorService • ManagedThreadFactory • ContextService • Services are accessed by application via: • resource injection using @Resource • JNDI lookup • default instances • Configured through vendor-defined properties 6
  • 8. Services ManagedExecutorService overview • Provides a familiar API for concurrent processing of tasks in Java EE • Extends java.util.concurrent.ExecutorService of Java SE concurrency API • Allow execution of asynchronous tasks on server managed threads • Tasks must implement either: – java.lang.Runnable – java.util.concurrent.Callable 7
  • 9. Services ManagedExecutorService API • Supports Java EE context propagation including JNDI naming, classloader, and security contexts • Not transactional contexts • Because the service is managed by the server, calling any of the lifecycle API methods results in IllegalStateException • Like Java SE, task(s) submission returns one or more Future(s). These are used to: • check for task execution status • wait for and retrieve task result • cancel task 8
  • 10. Services ManagedExecutorService Example @WebServlet(asyncSupported=true) public class MyServlet extends HttpServlet { @Resource ManagedExecutorService managedExecutorService; protected void doGet(HttpServletRequest request, HttpServletResponse response { final AsyncContext asyncContext = request.startAsync(); … Runnable myTask = new Runnable() { public void run() { asyncContext.complete(); } }; … Future future = managedExecutorService.submit(myTask); } 9
  • 11. Services ManagedScheduledExecutorService overview • Provides a familiar API for scheduling asynchronous tasks in Java EE • Supports Java EE context propagation including JNDI naming, classloader, and security contexts • Not transactional contexts • Used for scheduling tasks to run: • periodically • after specified delay • at some custom schedule 10
  • 12. Services ManagedScheduledExecutorService API • Extends both ManagedExecutorService and java.util.concurrent.ScheduledExecutorService interfaces • Like ManagedExecutorService, calling any of the lifecycle API methods results in IllegalStateException • In addition to schedule methods inherited from Java SE API, adds methods to support custom scheduling • schedule with Trigger interface 11
  • 13. Services ManagedScheduledExecutorService Trigger API • Interface implemented by application developer to support flexible, custom scheduling • Scheduling rules may be: • simple: a single, absolute date/time • complex: calendar logic • Trigger is submitted along with a task using a schedule method in ManagedScheduledExecutorService 12
  • 14. Services 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); } } 13
  • 15. Services ManagedThreadFactory overview • Provides the means for Java EE applications to obtain container-managed threads • Supports Java EE context propagation including JNDI naming, classloader, and security contexts • Not transactional contexts 14
  • 16. Services ManagedThreadFactory API • Extends java.util.concurrent.ThreadFactory • Same API: Thread.newThread(Runnable) • Supports Java EE context propagation including JNDI naming, classloader, and security contexts • Not transactional contexts • Threads from factory are: • contextualized with container context • required to implement the ManagableThread interface 15
  • 17. Services ManagedThreadFactory Example // Create a ThreadPoolExecutor using a ManagedThreadFactory. @Resource ManagedThreadFactory threadFactory; public ExecutorService getManagedThreadPool() { // All threads will be contextualized with the context // of the creating application component. return new ThreadPoolExecutor(5, 10, 5, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10), threadFactory); } 16
  • 18. Services ContextService overview • Creates dynamic proxy objects • objects are contextualized with container context upon creation • object methods execute with that captured context • Used by the other services to contextualize task and threads • May be used directly for advanced use cases: • request contextualization of Trigger methods • request contextualization of task listener notification methods • propagate custom contexts • Execution properties control how contextualization occurs 17
  • 19. Services ContextService API • Methods to create 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) 18
  • 20. Services ContextService Example public class MyRunnable implements Runnable { public void run() { System.out.println("MyRunnable.run with Java EE Context"); } } @Resource ThreadFactory threadFactory; @Resource ContextService ctxService; MyRunnable myRunnableInstance = new MyRunnable(); Runnable rProxy =ctxService.createContextualProxy( myRunnableInstance, Runnable.class); ExecutorService exSvc = Executors.newThreadPool(10, threadFactory); Future future = exSvc.submit(rProxy); 19
  • 21. Agenda • Introduction • Managed services • Additional APIs • Additional Resources 20
  • 22. Additional APIs Transaction Management • Transactions are not propagated to the threads on which tasks are run • Application may obtain a UserTransaction from JTA • Contextual proxy objects can run in the transaction context of the invoking thread, controlled by the execution property ManagedTask.TRANSACTION • default is ManagedTask.SUSPEND • ManagedTask.USE_TRANSACTION_OF_EXECUTION_THREAD 21
  • 23. Additional APIs ManagedTaskListener • Tasks events are emitted to listeners via ManagedTaskListener methods when tasks are: • submitted • unable to start or cancelled • starting • completed, either successfully or with exceptions • Useful for: • monitoring task progress • resubmitting failed tasks • ManagedTaskListener methods execute with unspecified context by default 22
  • 24. Additional APIs ManagedTask • Any task can optionally implement ManagedTask interface which provides: • ManagedTaskListener for lifecycle events notification • task identification • any desired execution properties • Other standard execution ManagedTask properties • IDENTITY_NAME – used to provide a task name • LONGRUNNING_HINT – hint of task length • TRANSACTION – controls transaction participation – SUSPEND – USE_TRANSACTION_OF_EXECUTION_THREAD 23
  • 25. Additional APIs ManagedExecutors • Similar to Executors utility class of Java SE concurrency package, contain methods for: • Creating a ManagedTask capable of receiving notifications via the specified ManagedTaskListener and with any specified execution properties • Testing whether current thread is a ManageableThread that has been marked for shutdown 24
  • 26. Agenda • Introduction • Managed services • Additional APIs • Additional Resources 25
  • 27. Additional Resources • JSR236 specification and API docs • http://jcp.org/en/jsr/detail?id=236 • JSR236 forum • http://concurrency-ee-spec.java.net • Java EE 7 API docs • http://docs.oracle.com/javaee/7/api 26
  • 28. Sampling of Related Sessions… • AAI-1713A: Introduction to Java EE 7 • Monday, 2-3pm, Mandalay Bay, Reef Ballroom E • AAI-1641A: Introduction to Web Sockets • Monday, 5-6pm, Mandalay Bay, Reef Ballroom E • AAI-1313A: Agile Development Using Java EE 7 with WebSphere Liberty Profile (LAB) • Tuesday, 8-10am, Mandalay Bay, South Seas Ballroom D • AAI-2236A: Using the New Java Concurrency Utilities with IBM WebSphere • Tuesday, 2-3pm, Mandalay Bay, Reef Ballroom D • AAI-2235A: OpenJPA and EclipseLink Usage Scenarios Explained • Wednesday, 5:30-6:30pm, Mandalay Bay, Surf Ballroom A • AAI-1610A: Configuring IBM WebSphere Application Server for Enterprise Messaging Needs • Wednesday, 5:30-6:30pm, Mandalay Bay, Surf Ballroom E • AAI-3085A: Don’t Wait! Develop Responsive Applications with Java EE7 Instead • Thursday, 10:30-11:30am, Mandalay Bay, Lagoon L 27
  • 30. Notices and Disclaimers Copyright © 2015 by International Business Machines Corporation (IBM). No part of this document may be reproduced or transmitted in any form without written permission from IBM. U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM. Information in these presentations (including information relating to products that have not yet been announced by IBM) has been reviewed for accuracy as of the date of initial publication and could include unintentional technical or typographical errors. IBM shall have no responsibility to update this information. THIS DOCUMENT IS DISTRIBUTED "AS IS" WITHOUT ANY WARRANTY, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL IBM BE LIABLE FOR ANY DAMAGE ARISING FROM THE USE OF THIS INFORMATION, INCLUDING BUT NOT LIMITED TO, LOSS OF DATA, BUSINESS INTERRUPTION, LOSS OF PROFIT OR LOSS OF OPPORTUNITY. IBM products and services are warranted according to the terms and conditions of the agreements under which they are provided. Any statements regarding IBM's future direction, intent or product plans are subject to change or withdrawal without notice. Performance data contained herein was generally obtained in a controlled, isolated environments. Customer examples are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual performance, cost, savings or other results in other operating environments may vary. References in this document to IBM products, programs, or services does not imply that IBM intends to make such products, programs or services available in all countries in which IBM operates or does business. Workshops, sessions and associated materials may have been prepared by independent session speakers, and do not necessarily reflect the views of IBM. All materials and discussions are provided for informational purposes only, and are neither intended to, nor shall constitute legal or other guidance or advice to any individual participant or their specific situation. It is the customer’s responsibility to insure its own compliance with legal requirements and to obtain advice of competent legal counsel as to the identification and interpretation of any relevant laws and regulatory requirements that may affect the customer’s business and any actions the customer may need to take to comply with such laws. IBM does not provide legal advice or represent or warrant that its services or products will ensure that the customer is in compliance with any law.
  • 31. Notices and Disclaimers (con’t) Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not tested those products in connection with this publication and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. IBM does not warrant the quality of any third-party products, or the ability of any such third-party products to interoperate with IBM’s products. IBM EXPRESSLY DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The provision of the information contained herein is not intended to, and does not, grant any right or license under any IBM patents, copyrights, trademarks or other intellectual property right. • IBM, the IBM logo, ibm.com, Bluemix, Blueworks Live, CICS, Clearcase, DOORS®, Enterprise Document Management System™, Global Business Services ®, Global Technology Services ®, Information on Demand, ILOG, Maximo®, MQIntegrator®, MQSeries®, Netcool®, OMEGAMON, OpenPower, PureAnalytics™, PureApplication®, pureCluster™, PureCoverage®, PureData®, PureExperience®, PureFlex®, pureQuery®, pureScale®, PureSystems®, QRadar®, Rational®, Rhapsody®, SoDA, SPSS, StoredIQ, Tivoli®, Trusteer®, urban{code}®, Watson, WebSphere®, Worklight®, X-Force® and System z® Z/OS, are trademarks of International Business Machines Corporation, registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at: www.ibm.com/legal/copytrade.shtml.
  • 32. Thank You Your Feedback is Important! Access the InterConnect 2015 Conference CONNECT Attendee Portal to complete your session surveys from your smartphone, laptop or conference kiosk.