Concurrency Utilities For Java EE Early Draft Preview

2y ago
19 Views
3 Downloads
452.56 KB
63 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Averie Goad
Transcription

Concurrency Utilities for Java EEEarly Draft PreviewDocument Version: Early Draft V. 0.1Document Date: Apr. 4, 2006Specification Leads:Chris D. Johnson, IBM CorporationRevanuru Naresh, BEA Systems, IncSee the Concurreny Utilities for Java EE interest erest/index.html) for instructions onhow to comment on this draft.

Copyright Notice Copyright International Business Machines Corp and BEA Systems, Inc. 2006. Allrights reserved.LicenseThis draft specification is not final. Any final specification that may be published willlikely contain differences, some of which may be substantial. Publication of this draftspecification is not intended to provide the basis for implementations of the specification.This draft specification is provided AS IS, with all faults. THERE ARE NOWARRANTIES, EXPRESS OR IMPLIED, INCLUDING WARRANTIES OFCONDITION OF TITLE OR NON-INFRINGEMENT. You may copy and display thisdraft specification provided that you include this notice and any existing copyright notice.Except for the limited copyright license granted above, there are no other licenses grantedto any intellectual property owned or controlled by any of the authors or developers ofthis material. No other rights are granted by implication, estoppel or otherwise.Feedback LicenseBEA Systems, Inc. and International Business Machines Corp (the "Companies") aredeveloping the "Concurrency Utilities for Java EE Specification" (the "Specification").The Companies would like to receive input, suggestions and other feedback ("Feedback")on the Specification. By providing feedback, you (on behalf of yourself if you are anindividual and your company if you are providing Feedback on behalf of the company)grant the Companies under all applicable intellectual property rights owned or controlledby you or your company a non-exclusive, non-transferable, worldwide, perpetual,irrevocable, royalty-free license to use, disclose, copy, publish, license, modify,sublicense or otherwise distribute and exploit Feedback you provide for the purpose ofdeveloping and promoting the Specification and in connection with any product thatimplements and complies with the Specification. You warrant to the best of yourknowledge that you have rights to provide this Feedback, and if you are providingFeedback on behalf of a company, you warrant that you have the rights to provideFeedback on behalf of your company. You also acknowledge that the Companies are notrequired to incorporate your Feedback into any version of the Specification.TrademarksJava and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in theUnited States, other countries, or both.iiEarly Draft Preview (Apr. 4, 2006)

Table of Contents123Introduction. 1-91.1Overview. 1-91.2Goals of this specification. 1-91.3Other Java Platform Specifications. 1-91.4Concurrency Utilities for Java EE Expert Group . 1-101.5Document Conventions. 1-10Overview. 2-112.1Container-Managed vs. Unmanaged Threads. 2-112.2Application Integrity. 2-112.3Container Thread Context. 2-122.3.1Contextual Invocation Points. 2-132.3.2Contextual Objects and Tasks. 2-132.4Usage with J2EE Connector Architecture . 2-142.5Security . 2-14Administered Objects. 3-153.1ManagedExecutorService . 3-153.1.1Application Component Provider’s Responsibilities. 3-153.1.2Application Assembler’s Responsibilities . 3-213.1.3Deployer’s Responsibilities . 3-213.1.4Java EE Product Provider’s Responsibilities. 3-213.1.5System Administrator’s Responsibilities. 3-243.1.6Server and Component-Managed ManagedExecutorServices. 3-253.1.7Quality of Service . 3-273.1.8Transaction Management. 3-283.2ManagedScheduledExecutorService. 3-293.2.1Application Component Provider’s Responsibilities. 3-293.2.2Application Assembler’s Responsibilities . 3-323.2.3Deployer’s Responsibilities . 3-323.2.4Java EE Product Provider’s Responsibilities. 3-333.2.5System Administrator’s Responsibilities. 3-353.2.6Server and Component-Managed ManagedExecutorServices. 3-35Concurrency Utilities for Java EEiii

3.2.7Quality of Service . 3-373.2.8Transaction Management. 3-373.3ContextService. 3-383.3.1Application Component Provider’s Responsibilities. 3-393.3.2Application Assembler’s Responsibilities . 3-433.3.3Deployer’s Responsibilities . 3-433.3.4Java EE Product Provider’s Responsibilities. 3-433.3.5Transaction Management. 3-453.4ManagedThreadFactory . 3-463.4.1Application Component Provider’s Responsibilities. 3-463.4.2Application Assembler’s Responsibilities . 3-493.4.3Deployer’s Responsibilities . 3-493.4.4Java EE Product Provider’s Responsibilities. 3-493.4.5System Administrator’s Responsibilities. 3-513.4.6Transaction Management. 3-513.54Distributable ManagedExecutorService . 3-523.5.1Distributable Requirements . 3-523.5.2Distributable with Affinity Requirements . 3-53Managed Objects . 4-554.1Object Name Key Properties . 4-564.2ManagedExecutorService extends J2EEManagedObject . 4-564.2.1Attribute Detail . 4-564.2.2Notifications. 4-574.3ManagedThreadFactory extends J2EEManagedObject. 4-574.3.1Attribute Detail . 4-574.3.2Notifications. 4-584.3.3Usage Example . 4-584.4ManagedThread extends J2EEManagedObject . 4-584.4.1Attribute Detail . 4-594.4.2Operation Detail. 4-604.4.3Usage Example . 4-614.5Notifications. 4-62Appendix AivChange History . 4-63Early Draft Preview (Apr. 4, 2006)

A.1Version 0.1: Early Draft Preview. 4-63Concurrency Utilities for Java EEv

List of FiguresFigure 1 - Concurrency Utilities for Java EE Architecture Diagram. 2-12Figure 2 - Contextual Task . 2-13Figure 3 - Server-Managed Thread Pool Executor Component Relationship . 3-25Figure 4 - Component-Managed Thread Pool Executor Component Relationship. 3-26Figure 5 - J2EEManagedObject detail with inheritance overview . 4-55Figure 6 - ManagedThread Managed Object Notification State Diagram. 4-62viEarly Draft Preview (Apr. 4, 2006)

List of TablesTable 1 - Typical Thread Pool Configuration Example. 3-23Table 2 - Batch Executor Configuration Example. 3-24Table 3 - OLTP Thread Pool Configuration Example. 3-24Table 4 - Typical Timer Configuration Example . 3-34Table 5 - Component Timer Configuration Example . 3-35Table 6 - All Contexts Configuration Example . 3-44Table 7 - OLTP Contexts Configuration Example . 3-44Table 8 - No Contexts Configuration Example . 3-45Table 9 - Normal ManagedThreadFactory Configuration Example. 3-50Table 10 - OLTP ManagedThreadFactory Configuration Example . 3-51Table 11 - Batch ManagedThreadFactory Configuration Example. 3-51Table 12 - Managed Object j2eeTypes and required parent-j2eeType keys . 4-56Concurrency Utilities for Java EEvii

viiiEarly Draft Preview (Apr. 4, 2006)

1Introduction1.1OverviewJava Platform, Enterprise Edition (Java EE and formally known as J2EE ) servercontainers such as the enterprise bean or web component container do not allow usingcommon Java SE concurrency APIs such as java.lang.Thread or java.util.Timerdirectly.The server containers provide runtime support for Java EE application components (suchas servlets and Enterprise JavaBeans (EJB )). They provide a layer betweenapplication component code and platform services and resources. All applicationcomponent code is run on a thread managed by a container and each container typicallyexpects all access to container-supplied objects to occur on the same thread.It is because of this behavior that application components are typically unable to reliablyuse other Java EE platform services from a thread that is not managed by the container.Java EE Product Providers (see chapter 2.10 of the Java 2 Enterprise EditionSpecification) also discourage the use of resources in a non-managed way, because it canpotentially undermine the enterprise features that the platform is designed to provide suchas availability, security, and reliability and scalability.This specification provides a simple, standardized API for using concurrency from JavaEE application components without compromising the integrity of the container whilestill preserving the fundamental benefits of the Java EE platform.1.2Goals of this specificationThis specification was developed with the following goals in mind: Preserve the fundamental capabilities and integrity of the Java EE platform. Utilize existing applicable Java EE platform services. Provide a simple yetflexible API for application component providers to design applications usingconcurrency design principles. Allow Java SE developers a simple migration path to the Java EE platform byproviding consistency between the Java SE and Java EE platforms. Allow application component providers to easily add concurrency to existing JavaEE applications. Support simple (common) and advanced concurrency patterns without sacrificingusability.1.3Other Java Platform SpecificationsThe following Java Platform specifications are referenced in this document: Concurrency Utilities Specification (JSR-166) J2EEConnector Architecture 1.5 (JSR-112)Concurrency Utilities for Java EE1-9

Introduction Java Platform Standard Edition Java Platform Standard Edition Java2 Platform, Enterprise Edition, Management Specification (JSR-77) Java Naming and Directory Interface Java Transaction API Java Transaction Service JDBC API Java Message Service (JMS)These specifications may be found at the Java web site: http://java.sun.com.1.4Concurrency Utilities for Java EE Expert GroupThis specification is the result of the collaborative work of the members of theConcurrency Utilities for Java EE Expert Group. These include the following presentand former expert group members; IBM Corporation: Chris D. Johnson, Billy Newport;BEA Systems, Inc: Revanuru Naresh, Stephan Zachwiega; Doug Lea; RedwoodSoftware: Andrew Evers; Tangosol: Cameron Purdy and Gene Gleyzer; Cyril Bouteille;Pierre Vignéras1.5Document ConventionsThe regular Times font is used for information that is prescriptive to this specification.The italic Times font is used for paragraphs that contain descriptive information, such asnotes describing typical use, or notes clarifying the text with prescriptive specification.The Courier font is used for code examples.1-10Early Draft Preview (Apr. 4, 2006)

2OverviewThe focus of this specification is on providing asynchronous capabilities to Java EEapplication components. This is largely achieved through extending the ConcurrencyUtilities API developed under JSR-166 and found in Java 2 Platform, Standard Edition 5(J2SE 5) in the java.util.concurrency package.The J2SE concurrency utilities provide an API that can be extended to support themajority of the goals defined in section 1.2. Application developers familiar with thisAPI in the Java SE platform can leverage existing code libraries and usage patterns withlittle modification.This specification has several aspects: Definition and usage of centralized, manageablejava.util.concurrent.ExecutorService objects in a Java EE application server. Usage of J2SE Concurrency Utilities in a Java EE application. Propagation of the Java EE container's runtime contextual information to otherthreads. Managing and monitoring the lifecycle of asynchronous operations in a Java EEApplication Component. Preserving application integrity.2.1Container-Managed vs. Unmanaged ThreadsJava EE application servers require resource management in order to centralizeadministration and protect application components from consuming unneeded resources.This can be achieved through the pooling of resources and managing a resource’slifecycle. Using Java SE concurrency utilities such as the java.util.concurrency API,java.lang.Thread and java.util.Timer in a server application component such as aservlet or EJB are problematic since the container and server have no knowledge of theseresources.By extending the java.util.concurrent API, application servers and Java EE containerscan become aware of the resources that are used and provide the proper execution contextfor the asynchronous operations to run with.This is largely achieved by providing managed versions of the predominantjava.util.concurrent.ExecutorService interfaces.2.2Application IntegrityManaged environments allow applications to coexist without causing harm to the overallsystem and isolate application components from one another. Administrators can adjustdeployment and runtime settings to provide different qualities of service, provisioning ofresources, scheduling of tasks, etc. Java EE containers also provide runtime contextservices to the application component. When using concurrency utilities such as those injava.util.concurrent, these context services need to be available.Concurrency Utilities for Java EE2-11

Overview2.3Container Thread ContextJava EE depends on various context information to be available on the thread wheninteracting with other Java EE services such as JDBC data sources, JMS providers andEJBs. When using Java EE services from a non-container thread, the followingbehaviors are required: Saving the application component thread’s container context. Identifying which container contexts to save and propagate. Applying a container context to the current thread. Restoring original thread's context.The contexts to be propagated are governed by the container but typically include namingcontext, class loader and security information.The relationships between the various Java EE architectural elements, containers andconcurrency constructs are shown in Figure 1. This diagram is an extension of the FigureJ2EE.2-1 in the J2EE 1.4 specification.Containers (represented here in a single rectangle) provide environments for applicationcomponents to safely interact with Java EE Standard Services (represented in therectangles directly below the EJB/Web Container rectangle). Three new concurrencyservices (represented by three dark-gray rectangles) allow application components to runasynchronous tasks and Java EE Standard Services to call application componentswithout violating container contracts.The arrows in the diagram illustrate various flows from one part of the Java EE platformto another.Application ServerEJB/Web FManagedExecutorServiceJTAJMXConnectorsJMSSAAJWeb va SEConcurrency ServicesFigure 1 - Concurrency Utilities for Java EE Architecture Diagram2-12Early Draft Preview (Apr. 4, 2006)

Overview2.3.1Contextual Invocation PointsContainer context and management constructs are propagated to component businesslogic at runtime using various invocation points on well known interfaces. Theseinvocation points or callback methods, here-by known as "tasks" will be referred tothroughout the specification: java.util.concurrent.Callableo call()java.lang.Runnableorun()The following callback methods are also contextual invocation points: current.TriggerogetNextRunTime()oskipRun()Other callback methods run with an unspecified context, but can be made contextualthrough the ContextService (see following sections), which can make any Java objectcontextual.2.3.2Contextual Objects and TasksTasks are concrete implementations of the Java SE java.util.concurrent.Callable andjava.lang.Runnable interfaces (see the Javadoc forjava.util.concurrent.ExecutorService). Tasks are units of work that represent acomputation or some business logic.A contextual object is any Java object instance that has a particular applicationcomponent's thread context associated with it (for example; user identity).When a task instance is submitted to a managed instance of an ExecutorService, the taskbecomes a contextual task. When the contextual task runs, the task behaves as if it werestill running in the container it was submitted with.Contextual TaskTaskContextFigure 2 - Contextual TaskConcurrency Utilities for Java EE2-13

Overview2.4Usage with J2EE Connector ArchitectureJ2EE Connector Architecture (JCA) 1.5 allows creating resource adapters which can pluginto any compatible Java EE application server. The JCA specification provides aWorkManager interface that allows asynchronous processing for the resource adapter. Itdoes not provide a mechanism for Java EE applications to interact with an adapter’sWorkManager.This specification addresses the need for Java EE applications to run application businesslogic asynchronously using a javax.util.concurrent.ManagedExecutorService orjava.util.concurrent.ExecutorService with ajavax.util.concurrent.ManagedThreadFactory. It is the intent that JCA 1.5 WorkManagerimplementations may choose to utilize or wrap thejava.util.concurrent.ExecutorService or other functionalities within this specificationwhen appropriate.Resource Adapters can access each of the Administered Objects described in thefollowing sections by looking them up in the JNDI global namespace.2.5SecurityThis specification largely defers most security decisions to the container and Java EEProduct Provider as defined in the Java 2 Platform Enterprise Edition Specification.If the container supports a security context, the Java EE Product Provider must propagatethat security context to the thread of execution.Application Component Providers should use the interfaces provided in this specificationwhen interacting with threads. If the Java EE Product Provider has implemented asecurity manager, some operations may not be allowed.2-14Early Draft Preview (Apr. 4, 2006)

3Administered ObjectsThis section introduces four programming interfaces for Java EE Product Providers toimplement (see J2EE.2.10 for a detailed definition of each of the roles described here).Instances of these interfaces must be made available to application components throughcontainers as administered objects: Section 3.1, "ManagedExecutorService" –The interface for submittingasynchronous tasks from a container. Section 3.2, "ManagedScheduledExecutorService" – The interface for schedulingtasks to run after a given delay or execute periodically. Section 3.3, "ContextService" – The interface for creating contextual objects. Section 3.4, "ManagedThreadFactory" – The interface for creating managedthreads.3.1ManagedExecutorServiceThe javax.util.concurrent.ManagedExecutorService is an interface that extends thejava.util.concurrent.ExecutorService interface. Java EE Product Providers provideimplementations of this interface to allow application components to run tasksasynchronously.3.1.1Application Component Provider’s ResponsibilitiesApplication Component Providers (application developers) (J2EE2.10.2) use aManagedExecutorService instance and associated interfaces to develop applicationcomponents that utilize the concurrency functions that these interfaces provide. Instancesfor these objects are retrieved using the Java Naming and Directory Interface (JNDI)Naming Context (J2EE.5).The Application Component Provider may use resource environment references to obtainreferences to a ManagedExecutorService instance as follows: Assign an entry in the application component’s environment to the referenceusing the reference type of: javax.util.concurrent.ManagedExecutorService.(See J2EE.5.5.1.2 for information on how resource environment references aredeclared in the deployment descriptor.) This specification recommends, but does not require, that all resourceenvironment references be organized in the appropriate subcontext of thecomponent’s environment for the resource type. For Example, allManagedExecutorService references should be declared in thejava:comp/env/concurrent subcontext. Look up the administered object in the application component’s environmentusing JNDI (J2EE.5).Concurrency Utilities for Java EE3-15

Administered ObjectsNote – Future versions of Java EE may have alternatives to JNDI such asannotations and resource injection. These alternatives may be added once thisspecification is incorporated into an umbrella JSR. Components create task classes by implementing the java.lang.Runnable orjava.util.concurrent.Callable interfaces. These task classes are typicallystored with the Java EE application component. Task instances are submitted to a ManagedExecutorService instance using any ofthe defined submit() or execute() methods. Task instances will run as anextension of the Java EE container instance that submitted the task as and mayinteract with Java EE resources as defined in other sections of this specification.Note – The use of resource environment references is best practice. Using the JNDIname of the ManagedExecutorService directly is allowed.It is important for Application Component Providers to identify and document therequired behaviors and service-level agreements for each requiredManagedExecutorService. See section 3.1.3.1 for a listing of required configurationattributes. The following example illustrates how the component can describe and utilizemultiple executors.3.1.1.1Usage ExampleIn this example, an application component is performing two asynchronous operationsfrom a servlet. One operation (reporter) is starting a task to generate a long runningreport. The other operations are short-running tasks that parallelize access to differentback-end databases (builders).Since each type of task has a completely different run profile, it makes sense to use twodifferent ManagedExecutorService resource environment references. The attributes ofeach reference are documented using the description tag within the deploymentdescriptor of the application component and later mapped by the Deployer.3.1.1.1.1 Reporter TaskThe Reporter Task is a long-running task that communicates with a database to generate areport. The task is run asynchronously using a ManagedExecutorService. The client canthen poll the server for the results.3.1.1.1.1.1 Resource Environment ReferenceThe following resource environment reference is added to the web.xml file for the webcomponent. The description reflects the desired configuration attributes (see 3.1.3.1):Note – Using the description for documenting the configuration attributes of theadministered object is optional. The format used here is only an example. Futurerevisions of Java EE specifications may formalize usages such as this. resource-env-ref description This executor is used for the application’s reporter task.This executor has the following requirements:Run Location:NA3-16Early Draft Preview (Apr. 4, 2006)

Administered ObjectsComp/Server:Server-AdministeredContext Info:Local Namespace /description resource-env-ref-name concurrent/BatchExecutor /resource-env-ref-name resource-env-ref-type javax.util.concurrent.ManagedExecutorService /resource-env-ref-type /resource-env-ref 3.1.1.1.1.2 Task DefinitionThe task itself simply uses a resource-reference to a JDBC data source, and uses aconnect/use/close pattern when invoking the Datasource.public class ReporterTask implements Runnable {String reportName;public ReporterTask(String reportName) {this.reportName reportName;}public void run() {// Run the named reportif("TransactionReport".equals(reportName)) {runTransactionReport();else if("SummaryReport".equals(reportName)) {runSummaryReport();}}}void runTransactionReport() {// Lookup the DataSource (the local naming// environment is inherited from the parent// component (servlet).InitialContext ctx new InitialContext();DataSource ds r");Connection con ds.getConnection();// Read/Write the data using our connection.// Commit and close.con.commit();con.close();}}3.1.1.1.1.3 Task SubmissionThe task is started by a HTTP client connecting to a servlet. The client specifies thereport name and other parameters to run. The handle to the task (the Future) is cached sothat the client can query the results of the report. The Future will contain the resultsonce the task has completed.public class AppServlet extends HTTPServlet implements Servlet {// Cache our executor instanceConcurrency Utilities for Java EE3-17

Administered ObjectsManagedExecutorService mes null;public void init(){// Lookup the executor and bean homesInitialContext ctx new InitialContext();mes concurrent/ReporterExecutor");}protected void doPost(HttpServletRequest req, HttpServletResponseresp) throws ServletException, IOException {// Get the name of the report to run from the input params // Assemble the header for the response.// Create a task instanceReporterTask reporterTask new ReporterTask(reportName);// Submit the task to the ManagedExecutorServiceFuture reportFuture mes.submit(reporterTask);// Cache the future somewhere (like the client's session)// The client can then poll the servlet to determine// the status of the report.// Tell the user that the report has been submitted.}}3.1.1.1.2 Builder TasksThis servlet accesses two different data sources and aggregates the results beforereturning the page contents to the user. Instead of accessing the data synchronously, it i

1.4 Concurrency Utilities for Java EE Expert Group This specification is the result of the collaborative work of the members of the Concurrency Utilities for Java EE Expert Group. These include the following present and former expert group m

Related Documents:

java.io Input and output java.lang Language support java.math Arbitrary-precision numbers java.net Networking java.nio "New" (memory-mapped) I/O java.rmi Remote method invocations java.security Security support java.sql Database support java.text Internationalized formatting of text and numbers java.time Dates, time, duration, time zones, etc.

Core Java Concurrency From its creation, Java has supported key concurrency concepts such as threads and locks. This guide helps Java developers working with multi-threaded programs to understand the core concurrency concepts and how to apply them. Topics covered in this guide include built-in Java

Java Version Java FAQs 2. Java Version 2.1 Used Java Version This is how you find your Java version: Start the Control Panel Java General About. 2.2 Checking Java Version Check Java version on https://www.java.com/de/download/installed.jsp. 2.3 Switching on Java Console Start Control Panel Java Advanced. The following window appears:

Bruksanvisning för bilstereo . Bruksanvisning for bilstereo . Instrukcja obsługi samochodowego odtwarzacza stereo . Operating Instructions for Car Stereo . 610-104 . SV . Bruksanvisning i original

Multi-Core in JAVA/JVM Tommi Zetterman Concurrency Prior to Java 5: Synchronization and Threads Java has been supporting concurrency from the beginning. Typical Java execution environment consists of Java Virtual Machine (JVM) which executes platform-in

devoted to designing concurrency control methods for RTDBS and to evaluating their performance. Most of these algorithms use serializability as correctness criteria and are based on one of the two basic concurrency control mechanisms: Pessimistic Concurrency Control [3, 12] or Optimistic Concurrency Control [2, 4, 5, 6, 11]. However, 2PL

Concurrency control Concurrency control in DBS methods for scheduling the operations of database transactions in a way which guarantees serializability of all transactions ("between system start and shutdown") Primary concurrency control methods – Locking (most important) – Optimistic concurrency control – Time stamps

Pile designers therefore looked at calculation based on theoretical soil mechanics. 16 Geotechnical Design to EC7 13 January 2017 Layer 1 Layer 2 Layer 3 L 1 L 2 L 3 Q s1 Q s2 Q s3 Q b Ultimate pile resistance Q u Q s Q b Traditional Pile Design to BS 8004. 17 Geotechnical Design to EC7 13 January 2017 Traditional Pile Design to BS 8004 The usual approach is to divide the ground into .