Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Scheduling and Tasks Spring scheduling.

Slides:



Advertisements
Similar presentations
7 Copyright © 2005, Oracle. All rights reserved. Maintaining State in J2EE Applications.
Advertisements

11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
How to Build Multi- threaded Applications in.NET Mazen S. Alzogbi Technology Specialist Microsoft Corporation.
50.003: Elements of Software Construction Week 10 Thread Pool.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Slide 1 of 10 Job Event Basics A Job Event is the name for the collection of components that comprise a scheduled job. On the iSeries a the available Job.
Java How to Program, 9/e CET 3640 Professor: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
1 The IIPC Web Curator Tool: Steve Knight The National Library of New Zealand Philip Beresford and Arun Persad The British Library An Open Source Solution.
Multithreading The objectives of this chapter are:
Enterprise Java Beans Welcome to the world of “Distributed System” Presented By: Sameer Nanda Date: 12/17/03.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
Introduction to EJB INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Created by the Community for the Community Building a RFID solution in BTS 09.
Understanding and Managing WebSphere V5
Workflow Framework There are many open-source workflow frameworks available such as: –OS Workflow -
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
© 2012 IBM Corporation Tivoli Workload Automation Informatica Power Center.
IBM Proof of Technology Discovering the Value of SOA with WebSphere Process Integration © 2005 IBM Corporation SOA on your terms and our expertise WebSphere.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Austin Java Users Group developerWorks article – µActor Library BARRY FEIGENBAUM, PH. D. 02/26/13.
Conditions and Terms of Use
95-843: Service Oriented Architecture 1 Master of Information System Management Service Oriented Architecture Lecture 10: Service Component Architecture.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Understanding the Bean Lifecycle An.
Replication & EJB Graham Morgan. EJB goals Ease development of applications –Hide low-level details such as transactions. Provide framework defining the.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
Enterprise Java Beans Java for the Enterprise Server-based platform for Enterprise Applications Designed for “medium-to-large scale business, enterprise-wide.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
Practical OOP using Java Basis Faqueer Tanvir Ahmed, 08 Jan 2012.
Middleware for FIs Apeego House 4B, Tardeo Rd. Mumbai Tel: Fax:
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Module 15 Monitoring SQL Server 2008 R2 with Alerts and Notifications.
Exploring Quartz Scheduler
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Forms with Spring MVC Handling Form.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring Remoting Simplifying.
An information and monitoring system for static and dynamic information about grid resources, applications, networks … RDBMS Servlet aware of API during.
Distribution and components. 2 What is the problem? Enterprise computing is Large scale & complex: It supports large scale and complex organisations Spanning.
37 Copyright © 2007, Oracle. All rights reserved. Module 37: Executing Workflow Processes Siebel 8.0 Essentials.
Computer Science 313 – Advanced Programming Topics.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 24 th, 2010 The University of Georgia.
A university for the world real R © 2009, Chapter 9 The Runtime Environment Michael Adams.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Views Rendering custom views.
Introduction to Enterprise JavaBeans Topics In Systems Architecture Barry Herbold
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
9 Copyright © 2009, Oracle. All rights reserved. Deploying and Reporting on ETL Jobs.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
CSC Multiprocessor Programming, Spring, 2012 Chapter 8 – Applying Thread Pools Dr. Dale E. Parson, week 10.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
8 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. BI Publisher Server: Administration and Security.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Overview of the Spring Framework Introducing.
Module 5: Managing Content. Overview Publishing Content Executing Reports Creating Cached Instances Creating Snapshots and Report History Creating Subscriptions.
…in java DThread Pools x. Thread Pools: Why? Source code updates – copy/paste of run/runnable method for each thread is exhausting There is overhead to.
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
Interstage BPM v11.2 1Copyright © 2010 FUJITSU LIMITED INTERSTAGE BPM ARCHITECTURE BPMS.
17 Copyright © 2006, Oracle. All rights reserved. Information Publisher.
Today Threading, Cont. Multi-core processing. Java Never Ends! Winter 2016CMPE212 - Prof. McLeod1.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Multithreading The objectives of this chapter are:
OPERATING SYSTEM CONCEPT AND PRACTISE
Debugging Dwight Deugo
Multithreaded Programming in Java
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
Debugging Dwight Deugo
Chapter 4: Threads.
Multithreading The objectives of this chapter are:
Presentation transcript:

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Scheduling and Tasks Spring scheduling and task execution abstractions

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 2 Topics in this session Introduction (2) TaskExecutor abstraction (13) Scheduling Framework overview (20) CommonJ container thread management (7)

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 3 The TaskExecutor Interface public interface TaskExecutor { void execute(Runnable task); } Standard Java Runnable

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4 Options for Task Execution (1) SyncTaskExecutor –Simple, synchronous execution SimpleAsyncTaskExecutor –Simple, asynchronous execution –Support throttling execution requests ThreadPoolTaskExecutor –Use the Java 5 ThreadPoolExecutor for scheduling –Highly configurable Thread pool size Rejection callbacks

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 5 Options for Task Execution (2) ConcurrentTaskExecutor –Uses a Java 5 Executor for scheduling –Prefer the ThreadPoolTaskExecutor TimerTaskExecutor –Uses the JDK Timer –Supports a basic delay before scheduling WorkManagerTaskExecutor –Uses the CommonJ WorkManager –Accessed from JNDI –Full Application Server support –More on this later

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 6 Configuring Simple TaskExecutors SyncTaskExecutor –No configuration options – its synchronous! SimpleAsyncTaskExecutor –concurrencyLimit The number of concurrent threads to allow (optional) –threadNamePrefix Add a prefix to the name of the created thread (optional) TimerTaskExecutor –timer The Timer instance to use (optional) –delay The delay, in millis, before starting the task (optional)

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 7 Understanding ThreadPoolTaskExecutor Backed by JDK 5.0 ThreadPoolExecutor Provides full pooling and queuing support Notification of rejected errors Allows for customized thread creation Extremely configurable –Pool size –Queue capacity –Rejection behaviour

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 8 ThreadPoolExecutor Concepts The thread pool –Configurable maximum and core sizes –Threads are not prestarted by default Customisable Thread creation –Using a ThreadFactory implementation Provides queuing capabilities for controlling how jobs are passed to the pool

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 9 Thread Creation Policy Thread count < core pool size –Create a thread Thread count >= core pool size –Favour queuing –Task served by existing thread Cannot queue? –Create new thread if thread count < max pool size –Else – reject task

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 10 Understanding Queuing (1) Three different strategies –Direct handoff SynchronousQueue Configurable in ThreadPoolTaskExecutor –Unbounded queues Unbounded LinkedBlockingQueue Configurable in ThreadPoolTaskExecutor –Bounded queues Bounded LinkedBlockingQueue Configurable in ThreadPoolTaskExecutor

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 11 Understanding Queuing (2) Direct handoff –Tasks are passed directly to threads in the pool –Can lead to exhaustion of the pool –Usually used with unbound max pool size Unbounded queues –Tasks are always queued when busy thread count = core pool size –Max pool size has not relevance –Ensures smooth level of throughput –Danger of unbounded queue growth Bounded queues –More difficult to tune than unbounded queues –Can help prevent reckless queue growth

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 12 Handling Rejected Tasks Configure a RejectedExecutionHander : public interface RejectedExecutionHandler { void rejectedExecution(Runnable r, ThreadPoolExecutor executor); }

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 13 Customising Thread Creation Configure a custom ThreadFactory : public interface ThreadFactory { Thread newThread(Runnable r); }

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 14 Configuring ThreadPoolTaskExecutor (1) corePoolSize –Specify the core pool size –Default is 1 maxPoolSize –Specify the max pool size –Default is Integer.MAX_VALUE (unbounded) keepAliveSeconds –Specifies how long a Thread (count > core pool size) are kept alive –Default is 60

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 15 Configuring ThreadPoolTaskExecutor (1) queueCapacity –Specifies the capacity of the queue –Defaults to Integer.MAX_VALUE for unbounded –Set to >0 for bounded queue –Set to 0 for a direct handoff rejectedExecutionHandler –Specify the RejectedExecutionHandler to use threadFactory –Specify the ThreadFactory to use –Defaults to Executors.defaultThreadFactory()

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Demo test.task.FibonacciLauncherTest

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 17 Introducing CommonJ Thread management for appserver container (c.f. EJB2) Standardised API sets –Created by IBM and BEA –Submitted to JCP Covers many areas –Service Data Objects (SDO) –WorkManager and TimerManager WorkManager is available in both WebLogic Server 9 and WebSphere 6

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 18 CommonJ and Spring Task Execution with WorkManager –Lookup WorkManager from JNDI –Use WorkManagerTaskExecutor Supports JNDI lookup internally Scheduling with TimerManager –Lookup TimerManager from JNDI –Use TimerManagerFactoryBean Support JNDI lookup internally Configure instances of ScheduledTimerListener to describe jobs

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19 Configuring WorkManagerExecutor <property name="workManagerName" value="wm/DvdCentralWorkManager"/> <property name="resourceRef" value="true"/> JNDI name for manager

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 20 Configuring WorkManagerExecutor (2) workManager –Specify the WorkManager instance to use workManagerName –Specify the JNDI name of the WorkManager –Automatic JNDI lookup jndiEnvironment –Specify the JNDI environment properties resourceRef –Is the JNDI name a resource reference? jndiTemplate –The JndiTemplate instance to use for lookups

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 21 Scheduling Concepts (1) Jobs/Task –The unit of work to perform within the configured schedule Schedule –The details governing the execution of the job –May be a simple start time and time period or a more complex expression such as 'every Monday at 10:00am' Initial delay –The initial delay before the commencement of the first execution

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 22 Scheduling Concepts (2) Period –The period between subsequent executions of a job –Exact semantics are governed by the fixed rate/delay option Fixed Rate –Indicates that period is rate at which jobs execute (i.e every 5 minutes) –May get executions in rapid succession if delays occur –Scheduled relative to the initial execution Fixed Delay –Indicates that period is the delay between termination of execution A and commencement of execution B. –Scheduled relative to the execution time of the previous execution

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 23 Options for Scheduling TimerFactoryBean –Uses the JDK Timer scheduler –Fixed rate/delay scheduling ScheduledExecutorFactoryBean –Uses the Java 5.0 ScheduledExecutorService –Fixed rate/delay scheduling SchedulerFactoryBean –Uses a Quartz scheduler –Extremely flexible scheduling support Use cron expressions TimerManagerFactoryBean –Uses a CommonJ TimerManager –Full ApplicationServer support –Fixed rate/delay scheduling

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 24 Scheduling with JDK Timer Configure an instance of TimerFactoryBean Associate instances of ScheduledTimerTask –Wrap the logic to invoke in a Runnable or TimerTask –Defines the execution details –Consider using MethodInvokingRunnable to automatically delegate to a service

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 25 Configuring TimerFactoryBean (1)

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 26 Configuring TimerFactoryBean (2) TimerFactoryBean Properties –daemon Should the timer run as a daemon thread? Default is true –scheduledTimerTasks The list of ScheduledTimerTask objects detailing the units of work and their schedules

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 27 Configuring TimerFactoryBean (3) ScheduledTimerTask Properties –delay The initial delay before the first execution –period The period between execution –fixedRate Indicates whether to use fixed rate (true) or fixed delay (false) execution Default is false –runnable Specifies the Runnable to run at each execution Wrapped in a TimerTask –timerTask Specifies the TimerTask to run at each execution

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 28 The MethodInvokingRunnable Class Wrapper around a bean Reflectively invokes a chosen method Removes the need to create Runnable classes for all tasks –Simply wrap your logic in a MethodInvokingRunnable instance Can't perform any additional logic in the task

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 29 Scheduling with ScheduledExecutorService Configure an instance of ScheduledExecutorFactoryBean Associate instances of ScheduledExecutorTask –Wrap the logic to invoke in a Runnable –Defines the execution details –Consider using MethodInvokingRunnable to automatically delegate to a service

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 30 Configuring ScheduledExecutorFactoryBean (1)

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 31 ScheduledExecutorFactoryBean Properties –poolSize Size of the core pool – max pool is not important Default is 1 –scheduledTimerTasks The list of ScheduledTimerTask objects detailing the units of work and their schedules Configuring ScheduledExecutorFactoryBean (2)

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 32 ScheduledExecutorTask Properties –delay The initial delay before the first execution –period The period between execution –fixedRate Indicates whether to use fixed rate (true) or fixed delay (false) execution Default is false –runnable Specifies the Runnable to run at each execution Wrapped in a TimerTask Configuring ScheduledExecutorFactoryBean (3)

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Demo test.scheduling.TimerSchedulingTest

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 34 Introducing Quartz Open-source scheduling engine from OpenSymphony Provides highly configurable scheduling options –Cron expressions –Exclusions with Calendars Persistence jobs Cluster support

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 35 Quartz Components (1) Job –Represents the unit of work to perform –Implemented by you StatefulJob –Marker interface for Jobs whose state should be maintained Scheduler –The main component in Quartz –Handles all the scheduling of Jobs Trigger –Controls the frequency with which scheduled Jobs are executed JobDetail –Stores a Job along with any Job data Calendar –Used to define inclusions/exclusions in a Triggers usual schedule JobStore –Mechanism used to store Job data –Default is RAMJobStore

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 36 Configuring a Scheduler in Spring Use SchedulerFactoryBean Important Properties –schedulerName Name of the scheduler instance Important when using multiple Schedulers –jobDetails List of JobDetails to register Referred to by Triggers –triggers The list of Triggers used to schedule Jobs May include the JobDetail directly

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 37 Persistent Jobs Stores Job schedule details –Runtime registered Jobs –StatefulJob state Enabling: –Add the Quartz tables to your database –Configure a DataSource for that database –Inject the DataSource into the SchedulerFactoryBean –Specify optional PlatformTransactionManager to use for registering Jobs and Triggers

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 38 Trigger Options (1) CronTrigger –Provides support for Unix-style cron expressions –Supports inclusions/exclusions with Calendars –Extremely powerful –Supports complex expressions such as: Every Monday, Wednesday and Friday at 10:00am The last Monday of every month at noon The last weekday of the month at 11:30am Every 5 seconds starting at the 3 rd second of the minute: – …

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Demo test.scheduling.QuartzSchedulingTest

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 40 Understanding Cron Expressions 3/5 * * * ? SecondsMinutesHoursDay of Month Day of Week Check out CronTrigger JavaDoc for more examples

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 41 More on Quartz… Misfire instructions Calendars –Fine-grained control over scheduling Multitude of configuration options SchedulerListeners, JobListeners and TriggerListeners –Monitor your Scheduler, Jobs and Triggers Cluster support

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 42 Configuring TimerManagerFactoryBean (1)

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 43 Configuring TimerManagerFactoryBean (2) Standard JNDI properties timerManager –The TimerManager instance to use timerManagerName –The JNDI name of the TimerManager scheduledTimerListeners –The list of ScheduledTimerListeners to configure with the TimerManager

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 44 Configuring TimerManagerFactoryBean (3) ScheduledTimerListener Properties –delay The initial delay before the first execution –firstTime The Date of the initial execution –period The period between execution –fixedRate Indicates whether to use fixed rate (true) or fixed delay (false) execution Default is false –runnable Specifies the Runnable to run at each execution Wrapped in a TimerListener –timerListener Specifies the TimerListener to run at each execution

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 45 Choosing a Scheduler As opposed to simple asynchronous execution using TaskExecutor Web applications –Use Quartz Simple-standalone environment –Use ScheduledExecutorService Multiple threads Highly configurable –Timer-based scheduling is okay for really simple cases –Consider Quartz for complex trigger support Strict Java EE environment –Consider WorkManager Threading support is built in –Most people still prefer Quartz however Can use a WorkManager as its thread pool through Spring!

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 46 Summary Comprehensive task execution support –ThreadPoolExecutor for Java 5 –Take advantage of CommonJ WorkManager if your platform supports it –SyncTaskExecutor is great for testing Multiple options for scheduling –Java 5 ScheduledExecutorService –CommonJ TimerManager –Quartz Its all about choice!

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 47 Scheduling in Spring 1.2 Two solutions for scheduling –JDK Timer Basic support for repeatable tasks Basic definition of schedule No clustering support No support for persistent tasks –Quartz Rich-schedule definitions using cron expressions Full clustering support Support for persistent jobs

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 48 What's new in Spring 2.0? Scheduling –JDK ScheduledExecutorService, Timer –CommonJ WorkManager –Application Server support Supported on WebLogic Server 9 and WebSphere 6 Task Execution –Simple API for task execution –Many different implementations Simple Threading ThreadPoolExecutor CommonJ WorkManager

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 49 More Information On the web: – – – Books: –Pro Spring – good Quartz coverage

Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 50 Topics in this session Introduction (2) TaskExecutor abstraction (13) Framework overview (20) CommonJ container thread management (7)