|By Di Li||
|May 5, 2005 03:00 PM EDT||
A custom multithreading framework is an efficient way to improve the performance of Java applications. It uses an asynchronous parallel pattern to implement the business process. However, its traditional Java thread-based implementation shouldn't be used in applications hosted in a J2EE Application Server because the threads in that framework are beyond the control of the J2EE Container. This article will discuss an intelligent solution for implementing custom multithreading by using message-driven beans. This message-driven bean based multithreading framework enables the J2EE container to manage threads and multiple MDBs to execute the business logic in parallel.
Java multithreading makes maximum use of the CPU by keeping the processor's idle time to minimum. To avoid the overhead of creating threads on-the-fly, every J2EE application server container has a default thread pool that contains a set of execute threads. The container can borrow one of the threads from the pool, and assign it a task. Upon completion of the task, the thread goes into a wait state ready to accept another assignment. The J2EE container monitors all execute threads in that pool. Custom threads are different from execute threads. They are created and controlled by the applications rather than the container. This article will introduce a solution implementing custom multithreading in a J2EE container.
Asynchronous Parallel Design PatternThe analysis model of the custom multithreading framework is based on the concept of asynchronous parallel design pattern. The pattern combines the advantages of delegate, asynchronous, and parallel design patterns. It's a model that consists of an asynchronous interface and a business engine. The business engine is composed of multiple parallel instances of business services, and fulfills the business processes. Figure 1 shows the class diagram representing the structure of the asynchronous parallel pattern.
The client doesn't have to have knowledge of the services that the back-end business engine provides. It simply sends the requests to the delegate, which adds the incoming requests to a mediator repository and returns a result to the client. The client doesn't go into a block state waiting for a response from the back-end business engine. The repository notifies the business engine when new requests are received. The multiple parallel instances of the services in the business engine then pick up the requests from the repository and process them concurrently. Figure 2 shows sequence diagrams that illustrate typical interactions among the components of the asynchronous parallel pattern.
Our example is based on an online brokerage system. We choose to model the process of an investor placing an order that is routed to the market for execution. I simplify the business scenario so we can focus on the custom multithreading framework.
Java Thread-Based Custom Multithreading Framework (CMF)The components of a Java thread-based CMF include a Thread Pool, Worker Thread, Task Dispatcher, Task, and Task Queue. The class diagram in Figure 3 shows the solution model of a Java thread-based multithreading framework.
The Task interface represents the abstract of the business cases fulfilled in the business process. Business cases are modeled by the Java class that implements the Task interface. For example, the Trade class represents the Stock Trade in a stock trading process. The business logic for processing each business case is implemented in the ‘execute' method of each class.
The TaskFIFOQueue and the TaskDispatcher classes implement the asynchronous interface of the asynchronous parallel pattern. The TaskFIFOQueue class is designed as an intermediary repository that stores unassigned tasks. The TaskDispatcher class works as the delegate of the framework, which receives clients' requests, creates an instance of a Java class implementing Task interface for each incoming request (such as Trade class), adds a new instance to TaskFIFOQueue. The client can continue with other activities without having to wait for its request to be processed. The code snippet in Listing 1 at the end of this article shows how to add or get a task from the TaskFIFOQueue.
The business engine of the asynchronous parallel pattern is implemented by the WorkThread class and the ThreadPool class. The WorkThread class provides the threads that will process the assigned task. Each instance of the WorkThread class is a custom thread, created and controlled by the application. The Thread-Pool class serves as the central control point to manage custom threads. Using an object of the ThreadPool class to store running threads lets us allocate custom threads in a predictable way, reuse an existing thread for multiple tasks, and save time for thread instantiation and initialization. The code in Listing 2 at the end of this article demonstrates how to implement the business engine.
When the TaskDispatcher receives a request from a client, it creates an instance of a particular Task-type class, such as the Trade class, and adds the instance to the TaskFIFOQueue. The TaskFIFOQueue then notifies all waiting threads that a new task is ready to be picked up. The current active WorkerThread gets the task from the TaskFIFOQueue and starts to process the task by running the execute() method of the particular Task-type class. After the WorkThreads finishes the task, it goes into a wait state and is ready to accept the next task. The sequence diagram in Figure 4 illustrates the sample collaborations for the CMF.
Although Java thread-based CMF provides an efficient solution to improve the overall performance of Java applications, it shouldn't be used in applications hosted in the J2EE application server. Java thread-based CMF is discouraged in the J2EE applications for the following reasons.
J2EE Application Server Can't Control Custom Threads
The J2EE application server container is configured to manage all the threads in the Java Virtual Machine. The threads from the CMF won't carry the implicit context that a container normally puts on a thread. The container loses control over the custom threads created explicitly by the CMF because it's not aware of their existence.
Consequently, if a custom thread fails, the container will not be able to detect the failure and so can't recover the thread - either by reclaiming the resources occupied by the particular thread or by restarting it to complete the assigned task. The presence of unmanaged failed threads in the application server can seriously impact the stability, scalability, and performance of the application server.
Thread- Based CMF Affects the Load Balancing in the J2EE Application Cluster
Since a J2EE application server isn't aware of the custom threads in the CMF, it's also not aware of the work being done by the threads, and so won't account for the impact that the additional threads have on the overall workload of the server. This will affect the load balancing of the J2EE application cluster. It will potentially over-assign work to the server, and result in significant throughput or performance problems with the server.
The EJB 2.0 specification integrates EJB with JMS, and defines a new type of Enterprise JavaBean: Message-Driven Bean (MDB). It enables the EJB container to support the asynchronous parallel design pattern. Because the basic theories of the Java thread-based CMF don't negatively impact the application server runtime, we'll use the same analysis model to design the MDB-based CMF. For the purpose of demonstration, the MDB-based framework will be implemented and deployed on WebLogic Server 8.1.
The cloud. Like a comic book superhero, there seems to be no problem it can’t fix or cost it can’t slash. Yet making the transition is not always easy and production environments are still largely on premise. Taking some practical and sensible steps to reduce risk can also help provide a basis for a successful cloud transition. A plethora of surveys from the likes of IDG and Gartner show that more than 70 percent of enterprises have deployed at least one or more cloud application or workload. Yet a closer inspection at the data reveals less than half of these cloud projects involve production...
Nov. 29, 2015 07:00 AM EST Reads: 489
Continuous processes around the development and deployment of applications are both impacted by -- and a benefit to -- the Internet of Things trend. To help better understand the relationship between DevOps and a plethora of new end-devices and data please welcome Gary Gruver, consultant, author and a former IT executive who has led many large-scale IT transformation projects, and John Jeremiah, Technology Evangelist at Hewlett Packard Enterprise (HPE), on Twitter at @j_jeremiah. The discussion is moderated by me, Dana Gardner, Principal Analyst at Interarbor Solutions.
Nov. 29, 2015 06:45 AM EST Reads: 737
Discussions of cloud computing have evolved in recent years from a focus on specific types of cloud, to a world of hybrid cloud, and to a world dominated by the APIs that make today's multi-cloud environments and hybrid clouds possible. In this Power Panel at 17th Cloud Expo, moderated by Conference Chair Roger Strukhoff, panelists addressed the importance of customers being able to use the specific technologies they need, through environments and ecosystems that expose their APIs to make true change and transformation possible.
Nov. 29, 2015 06:00 AM EST Reads: 550
Too often with compelling new technologies market participants become overly enamored with that attractiveness of the technology and neglect underlying business drivers. This tendency, what some call the “newest shiny object syndrome” is understandable given that virtually all of us are heavily engaged in technology. But it is also mistaken. Without concrete business cases driving its deployment, IoT, like many other technologies before it, will fade into obscurity.
Nov. 29, 2015 06:00 AM EST Reads: 372
Microservices are a very exciting architectural approach that many organizations are looking to as a way to accelerate innovation. Microservices promise to allow teams to move away from monolithic "ball of mud" systems, but the reality is that, in the vast majority of organizations, different projects and technologies will continue to be developed at different speeds. How to handle the dependencies between these disparate systems with different iteration cycles? Consider the "canoncial problem" in this scenario: microservice A (releases daily) depends on a couple of additions to backend B (re...
Nov. 29, 2015 05:00 AM EST Reads: 458
The Internet of Things is clearly many things: data collection and analytics, wearables, Smart Grids and Smart Cities, the Industrial Internet, and more. Cool platforms like Arduino, Raspberry Pi, Intel's Galileo and Edison, and a diverse world of sensors are making the IoT a great toy box for developers in all these areas. In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists discussed what things are the most important, which will have the most profound effect on the world, and what should we expect to see over the next couple of years.
Nov. 29, 2015 04:30 AM EST Reads: 483
Container technology is shaping the future of DevOps and it’s also changing the way organizations think about application development. With the rise of mobile applications in the enterprise, businesses are abandoning year-long development cycles and embracing technologies that enable rapid development and continuous deployment of apps. In his session at DevOps Summit, Kurt Collins, Developer Evangelist at Built.io, examined how Docker has evolved into a highly effective tool for application delivery by allowing increasingly popular Mobile Backend-as-a-Service (mBaaS) platforms to quickly crea...
Nov. 29, 2015 04:00 AM EST Reads: 373
Growth hacking is common for startups to make unheard-of progress in building their business. Career Hacks can help Geek Girls and those who support them (yes, that's you too, Dad!) to excel in this typically male-dominated world. Get ready to learn the facts: Is there a bias against women in the tech / developer communities? Why are women 50% of the workforce, but hold only 24% of the STEM or IT positions? Some beginnings of what to do about it! In her Day 2 Keynote at 17th Cloud Expo, Sandy Carter, IBM General Manager Cloud Ecosystem and Developers, and a Social Business Evangelist, wil...
Nov. 29, 2015 03:00 AM EST Reads: 594
PubNub has announced the release of BLOCKS, a set of customizable microservices that give developers a simple way to add code and deploy features for realtime apps.PubNub BLOCKS executes business logic directly on the data streaming through PubNub’s network without splitting it off to an intermediary server controlled by the customer. This revolutionary approach streamlines app development, reduces endpoint-to-endpoint latency, and allows apps to better leverage the enormous scalability of PubNub’s Data Stream Network.
Nov. 29, 2015 03:00 AM EST Reads: 337
Apps and devices shouldn't stop working when there's limited or no network connectivity. Learn how to bring data stored in a cloud database to the edge of the network (and back again) whenever an Internet connection is available. In his session at 17th Cloud Expo, Ben Perlmutter, a Sales Engineer with IBM Cloudant, demonstrated techniques for replicating cloud databases with devices in order to build offline-first mobile or Internet of Things (IoT) apps that can provide a better, faster user experience, both offline and online. The focus of this talk was on IBM Cloudant, Apache CouchDB, and ...
Nov. 29, 2015 02:45 AM EST Reads: 421
I recently attended and was a speaker at the 4th International Internet of @ThingsExpo at the Santa Clara Convention Center. I also had the opportunity to attend this event last year and I wrote a blog from that show talking about how the “Enterprise Impact of IoT” was a key theme of last year’s show. I was curious to see if the same theme would still resonate 365 days later and what, if any, changes I would see in the content presented.
Nov. 29, 2015 01:00 AM EST Reads: 436
Cloud computing delivers on-demand resources that provide businesses with flexibility and cost-savings. The challenge in moving workloads to the cloud has been the cost and complexity of ensuring the initial and ongoing security and regulatory (PCI, HIPAA, FFIEC) compliance across private and public clouds. Manual security compliance is slow, prone to human error, and represents over 50% of the cost of managing cloud applications. Determining how to automate cloud security compliance is critical to maintaining positive ROI. Raxak Protect is an automated security compliance SaaS platform and ma...
Nov. 28, 2015 08:00 PM EST Reads: 433
The Internet of Things (IoT) is growing rapidly by extending current technologies, products and networks. By 2020, Cisco estimates there will be 50 billion connected devices. Gartner has forecast revenues of over $300 billion, just to IoT suppliers. Now is the time to figure out how you’ll make money – not just create innovative products. With hundreds of new products and companies jumping into the IoT fray every month, there’s no shortage of innovation. Despite this, McKinsey/VisionMobile data shows "less than 10 percent of IoT developers are making enough to support a reasonably sized team....
Nov. 28, 2015 01:00 PM EST Reads: 479
Just over a week ago I received a long and loud sustained applause for a presentation I delivered at this year’s Cloud Expo in Santa Clara. I was extremely pleased with the turnout and had some very good conversations with many of the attendees. Over the next few days I had many more meaningful conversations and was not only happy with the results but also learned a few new things. Here is everything I learned in those three days distilled into three short points.
Nov. 28, 2015 12:00 PM EST Reads: 341
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo 2016 in New York and Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound cha...
Nov. 28, 2015 12:00 PM EST Reads: 555
DevOps is about increasing efficiency, but nothing is more inefficient than building the same application twice. However, this is a routine occurrence with enterprise applications that need both a rich desktop web interface and strong mobile support. With recent technological advances from Isomorphic Software and others, rich desktop and tuned mobile experiences can now be created with a single codebase – without compromising functionality, performance or usability. In his session at DevOps Summit, Charles Kendrick, CTO and Chief Architect at Isomorphic Software, demonstrated examples of com...
Nov. 28, 2015 11:45 AM EST Reads: 409
As organizations realize the scope of the Internet of Things, gaining key insights from Big Data, through the use of advanced analytics, becomes crucial. However, IoT also creates the need for petabyte scale storage of data from millions of devices. A new type of Storage is required which seamlessly integrates robust data analytics with massive scale. These storage systems will act as “smart systems” provide in-place analytics that speed discovery and enable businesses to quickly derive meaningful and actionable insights. In his session at @ThingsExpo, Paul Turner, Chief Marketing Officer at...
Nov. 28, 2015 11:15 AM EST Reads: 417
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
Nov. 28, 2015 11:00 AM EST Reads: 517
In his General Session at 17th Cloud Expo, Bruce Swann, Senior Product Marketing Manager for Adobe Campaign, explored the key ingredients of cross-channel marketing in a digital world. Learn how the Adobe Marketing Cloud can help marketers embrace opportunities for personalized, relevant and real-time customer engagement across offline (direct mail, point of sale, call center) and digital (email, website, SMS, mobile apps, social networks, connected objects).
Nov. 28, 2015 10:30 AM EST Reads: 318
We all know that data growth is exploding and storage budgets are shrinking. Instead of showing you charts on about how much data there is, in his General Session at 17th Cloud Expo, Scott Cleland, Senior Director of Product Marketing at HGST, showed how to capture all of your data in one place. After you have your data under control, you can then analyze it in one place, saving time and resources.
Nov. 28, 2015 10:00 AM EST Reads: 199