• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Java EE Concurrency Utilities
 

Java EE Concurrency Utilities

on

  • 11,387 views

This fast-faced, code-centric lightning talk covers the new Java EE Concurrency (aka Concurrency Utilities for Java EE) API. ...

This fast-faced, code-centric lightning talk covers the new Java EE Concurrency (aka Concurrency Utilities for Java EE) API.

Java EE Concurrency is a long-awaited standard for enabling Java SE util.concurrent style low-level concurrency capabilities in a safe, secure, scalable and reliable way in managed Java EE environments. The API provides managed versions of executor services, scheduled executors, thread factories, tasks and much, much more that you can use in a portable fashion across any container without risking container integrity.

Statistics

Views

Total Views
11,387
Views on SlideShare
8,382
Embed Views
3,005

Actions

Likes
3
Downloads
56
Comments
0

26 Embeds 3,005

http://java.dzone.com 1653
https://blogs.oracle.com 1159
http://cloud.feedly.com 96
http://www-ig-opensocial.googleusercontent.com 16
http://www.feedspot.com 14
http://www.newsblur.com 9
http://feedreader.com 7
http://summary 6
http://prsync.com 5
http://newsblur.com 5
http://digg.com 4
http://127.0.0.1 4
http://blogs.oracle.com 4
http://www.dzone.com 4
http://architects-portal.cybage.com 3
http://blog.atherio.com 3
http://cuckoo9.okoza.com 2
http://news.google.com 2
http://bloggers1033.rssing.com 2
https://inoreader.com 1
http://rritw.com 1
http://translate.googleusercontent.com 1
http://www.365dailyjournal.com 1
http://fr.flavors.me 1
http://silverreader.com 1
http://www.google.co.uk 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Java EE Concurrency Utilities Java EE Concurrency Utilities Presentation Transcript

    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.2Concurrency Utilities for theJava EE PlatformReza RahmanGlassFish/Java EE Evangelistreza.rahman@oracle.com
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3The following is intended to outline our general product direction. It is intendedfor information purposes only, and may not be incorporated into any contract.It is not a commitment to deliver any material, code, or functionality, and shouldnot be relied upon in making purchasing decisions. The development, release,and timing of any features or functionality described for Oracle’s productsremains at the sole discretion of Oracle.
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4Concurrency Utilities for the Java EE Platform Provides low-level asynchronous processing capabilities to Java EEapplication components in a safe, reliable, consistent manner Extension of Java SE Concurrency Utilities APIs
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5Primary Interfaces Extends existing Java SE concurrency utilities– ManagedExecutorService– ManagedScheduledExecutorService– ManagedThreadFactory New interface– ContextService Lookup via JNDI or @Resource Default objects– java:comp/DefaultManagedExecutorService etc...
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6ManagedExecutorService For running tasks asynchronously on threads provided by Java EEcontainer Container context captured from submitting thread to be applied onexecution thread Not transactional – tasks should use their own transactionsOverview
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7ManagedExecutorService Extends from java.util.concurrent.ExecutorService No additions Lifecycle APIs disabled – throws IllegalStateException– awaitTermination, isTerminated, isShutdown, shutdown, shutdownNowAPI
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8ManagedExecutorServiceAPIvoid execute(Runnable command);<T> Future<T> submit(Callable<T> task);Future<?> submit(Runnable task);<T> Future<T> submit(Runnable task, T result);<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks);<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,long timeout, TimeUnit unit);<T> T invokeAny(Collection<? extends Callable<T>> tasks)<T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout,TimeUnit unit);
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9ManagedExecutorServiceExample@Resource(name=“concurrent/myExecutor”)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 © 2012, Oracle and/or its affiliates. All rights reserved.10ManagedScheduledExecutorService For scheduling tasks to run after a given delay, periodically, or at somecustom schedule Extends from ManagedExecutorService andjava.util.concurrent.ScheduledExecutorServiceOverview
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11ManagedScheduledExecutorServiceAPI<V> ScheduledFuture<V> schedule(Callable<V> callable, long delay,TimeUnit unit);ScheduledFuture<V> 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);ScheduledFuture<?> schedule(Runnable command, Trigger trigger);<V> ScheduledFuture<V> schedule(Callable<V> callable, Trigger trigger);
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12ManagedScheduledExecutorServiceTriggerinterface Trigger {// Return true if you want to skip the// currently-scheduled execution.boolean skipRun(LastExecution lastExecutionInfo,Date scheduledRunTime);// Retrieves the time in which to run the task// next. Invoked during submit time and after// each task has completed.Date getNextRunTime(LastExecution lastExecutionInfo,Date taskScheduledTime);}
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13Managed[Scheduled]ExecutorServiceManagedTaskListener Listeners can be registered with the task when submitted toManaged[Scheduled]ExecutorService API– taskSubmitted – The task was submitted to the executor– taskAborted – The task was unable to start or was cancelled– taskStarting – The task is about to start– taskDone – The task has completed (successfully, exception, cancelled,aborted, or rejected) The listener method runs in unspecified context, but can be configuredto run in the same container context as the task
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14Managed[Scheduled]ExecutorServiceManagedTask Any task submitted to an ManagedExecutorService orManagedScheduledExecutorService can optionally implementManagedTask API– Map<String, String> getExecutionProperties()– ManagedTaskListener getManagedTaskListener() Execution properties– CONTEXTUAL_CALLBACK_HINT– IDENTITY_NAME– LONGRUNNING_HINT
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15ManagedTaskRegistering ManagedTaskListener// Runnable implements ManagedTaskpublic class TaskWithListener implements Runnable, ManagedTask {...public ManagedTaskListener getManagedTaskListener() {return aManagedTaskListener;}}// Or use ManagedExecutors utility method to associate// a ManagedTaskListener to a taskRunnable aTask;ManagedTaskListener myTaskListner;Runnable taskWithListener =ManagedExecutors.managedTask(aTask, myTaskListener);// Submit taskWithListener to a ManagedExecutorService
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16Where to Find Out More Read the draft spec and API docs athttp://concurrency-ee-spec.java.net GlassFish 4.0– http://glassfish.java.net/– http://dlc.sun.com.edgesuite.net/glassfish/4.0/promoted/ Reference Implementation– http://java.net/projects/cu-javaee Slide Deck– http://www.slideshare.net/reza_rahman
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17Graphic Section Divider
    • Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18