Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java EE Concurrency Utilities

14,290 views

Published on

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.

Published in: Technology
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Java EE Concurrency Utilities

  1. 1. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1
  2. 2. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.2Concurrency Utilities for theJava EE PlatformReza RahmanGlassFish/Java EE Evangelistreza.rahman@oracle.com
  3. 3. 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.
  4. 4. 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
  5. 5. 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...
  6. 6. 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
  7. 7. 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
  8. 8. 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);
  9. 9. 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();...
  10. 10. 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
  11. 11. 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);
  12. 12. 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);}
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17Graphic Section Divider
  18. 18. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18

×