Ivan Kiselev

Subscribe to Ivan Kiselev: eMailAlertsEmail Alerts
Get Ivan Kiselev: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Java Developer Magazine

Java Developer : Article

Achieving Thread Synchronization & Parallelized Execution in Java

Building multithreaded execution capabilities in a Java application

Applications that have high performance as a quality goal would motivate a programmer to design and build them as multithreaded apps. The Java programming environment provides for parallel execution of logic by using threads. However, this is at a lower level and provides limited capability.

To make multithreading work successfully in an application, programmers have to handle higher-level concerns like synchronizing the execution of multiple threads, handling exceptions in threads executing in parallel, limiting the number of threads in the runtime environment, and thread pooling. Java programmers need an easy-to-use, standardized, trusted, and efficient library to take care of concurrent programming. The concurrent utility developed by Doug Lea is a very popular and useful library for this purpose. By taking the example of a BPMS process execution platform's implementation, we'll look at how we could use the concurrent utility's classes to build a multi-threaded application. This is based on my experience designing and building a BPMS server in Java.

One scenario where concurrent programming is very important is in a business process management system (BPMS). The runtime part of a BPMS, generally referred to as the BPMS server, handles the execution or automation of business processes. In this article, let's look at how we could use the concurrent utility's classes to build a multithreaded application by using a BPMS process execution platform based on my experience in designing and building the same in Java as an example.

Concurrent Utility
Doug Lea, a professor at the State University of New York (SUNY) at Oswego, created a concurrent library (util.concurrent package) in the late '90s that could help handle multithreaded scenarios in Java applications and he made the library openly available. It became so popular with Java programmers that it was included in Java 5.0 (JDK 1.5) as the Java.util.concurrent package. For concurrent programming, it defines a few interfaces and provides their implementations, which are efficient, well-tested, and standardized. The last version prior to its inclusion in JDK 1.5 was util.concurrent 1.3.4. This was the version that we originally used while building our BPMS, since BPMS was based on JDK1.4. To make the future migration to JDK1.5 easier, we subsequently replaced the 1.3.4 release of the concurrent library with the backport of the main java.util.concurrent Java 5.0 classes made available by Dawid Kurzyniec. The package name for the backport is edu.emory.mathcs.backport.Java.util.concurrent.

At a broad level, the library provides the following components: an executor for thread-based execution, synchronizers that aid in synchronizing thread executions, queues that are thread-safe and scalable, concurrent collections, and timing for time handling. From these, we used wxecutor and synchronizers heavily in the BPMS runtime platform and I will explain the usage details in subsequent sections. Executor is used to execute tasks in threads; we could run the task in a separate thread (new) or run the task in the same thread as the current one. ThreadPoolExecutor is an executor implementation that executes the task by utilizing a thread from the managed thread pool. This gives better performance due to the reduced overhead; it also manages the resources (threads) better including bounding them.

More Stories By Parameswaran Seshan

Parameswaran Seshan performs the role of an independent educator/trainer, architect, researcher, and architecture consultant, in Information Technology (IT). He teaches architecture, design and technology related courses. Prior to this, he worked as Principal (Education and Research) with E-Comm Research Lab, Infosys Technologies Limited, Bangalore, India. He has more than 15 years of work experience in the IT industry, involving teaching, architecture, research, and programming. His areas of interest include Enterprise Architecture, Process-centric architecture, Intelligent software systems, Intelligent agents, software architecture, Business Process Management systems, Web services and Java. You can reach Parameswaran at, contact {at} bitsintune [dot] com.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.