Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Thread Pooling and Executors in Java 5 - configuring an executor
Configuration options for an Executor

Thread Pooling in Java 5

Thread Pooling in Java 5 is configured using one of the implementations of the executor interface.
One implementation is ThreadPoolExecutor. This implementation, as the name, suggests is configurable with the no of threads in the pool, the maximum pool size, a rejection handler, a thread factory, a work queue.

Executor <---------- ExecutorService <-------- AbstractExecutorService <----------- ThreadPoolExecutor <---------- ScheduledThreadPoolExecutor (This is the depiction of the hierarchy => Executor is extended by the ExecutorService interface which is realized by the AbstractExecutorService class and so on)

The significance of these configurable parameters is listed below barring the self explanatory parameters:

  1. Rejection Handler / Saturation Policies: This is an implementation that determines the policy to be used in cases when a task is to be rejected. The rejection could be because of many reasons: the work queue is filled up, the executor is shutting down etc. There are predefined policies as well that are detailed in the JavaDocs.
  2. Thread Factory: An implementation of this will be used by the executor (ThreadPoolExecutor in this case) to create the pool thread. This is very useful since a customized thread factory implementation can be setup to perform a variety of customizations. Such as: specifying an UncaughtExceptionHandler on a per thread basis.
  3. Work Queue: This is where the tasks that are to be executed are held at. One could configure the work queue to be of a certain size. The pool threads will pop off this work queue and execute the tasks based on a certain policy that in turn is based on the BlockingQueue implementation. For instance: if the work queue is a PriorityQueue then tasks will be popped off based on priority.


A ScheheduledThreadPoolExecutor can additionally be setup to execute tasks periodically. A task can be scheduled to execute after a given delay and at a specified interval thereafter. If a task takes longer than the interval specified to execute then another thread is spawned or reused from the pool to execute the task. This is different from a Timer in terms of the task always is executed after the interval even if the preceding task is still running.

Difference between executor obtained from Executors and directly instantiating the ThreadPoolExecutor or ScheduledThreadPoolExecutor

The distinguishing facet is that the Executor obtained from the new****Thread*** methods in Executors is preconfigured and cannot be reconfigured while it is running. Of course one can cast it to ThreadPoolExecutor (or any other implementation) and then invoke it's configuration API but it is discouraged since that would require coupling the caller and the callee.
An Executor so obtained is preconfigured in terms of:
. Saturation Policies
. Thread Factory
. Work Queue

In order to customize, one would need to instantiate the appropriate Executor such as ThreadPoolExecutor or ScheduledThreadPoolExecutor.

About Gaurav Khanna
I have 12 years of Java with special emphasis on the server and have architected and designed many systems and components. I have been employed as lead engineer at Hyperion Solutions in the Common Technology / Platform group (acquired by Oracle corp). I have been employed at Apple most recently and Hyperion prior to that. I have a Bachelors in Technology in Computer Science and Engineering. I have led teams and mentored engineers in my earlier assignments as well. Have run a 6:30 mile, practiced boxing and jiu-jitsu, am a regular at the gym and like the outdoors. I would like to continue in technology perhaps moving on to establishing a tech startup. You would find me here or at my blog: http://khanna111.com/wordPressBlog

Latest Cloud Developer Stories
As a result, it said, of “customer feedback and evolving usage patterns,” Microsoft cut the price of its cloud-ified SQL Azure database 48%–75% for databases larger than 1GB and introduced a new entry-level 100MB model. It blogged that it’s noticed that many projects start smal...
Wide and cheap availability of cloud-based media services is upon us. With the transformations these services are already bringing to the consumption of music, video and interactive media, change has likewise come to professional workflows. Documents in 2012 are read, written, co...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical ...
Fresh off a happy quarter, Rackspace said Thursday that it’s bought SharePoint911, one of those you-never-heard-of-them outfits that does SharePoint consulting, training and JumpStart services so it can deliver newfangled SharePoint services along with its existing SharePoint hos...
Cloud is a shift from the focus on underlying technology implementation to leveraging existing implementations and further building upon them. Cloud orchestration or a network of clouds is the wave of the future where these clouds can operate with elasticity, scalability, and eff...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE