Java Design Pattern for Concurrent Multiple Object Operations - Illustrated in iManager Plugin development
Novell Cool Solutions: Feature
By R Sathish
Digg This - Slashdot This Posted: 22 Dec 2004 |
Problem: To concurrently process operations which involve a collection of objects, like deleting 'n' objects, updating 'n' objects.
Existing Solution: Write the code in a class, make it extend Thread and execute it. Iterate over the collection of objects, catch all exceptions.
Design Pattern: Separates application specific and language specific code.
![](http://www.novell.com/coolsolutions/img/jdp1.gif)
![](http://www.novell.com/coolsolutions/img/jdp2.gif)
![](http://www.novell.com/coolsolutions/img/jdp3.gif)
![](http://www.novell.com/coolsolutions/img/jdp4.gif)
![](http://www.novell.com/coolsolutions/img/jdp5.gif)
doMooParallel executes MooCode in MooThreads
User implements MooCode and calls doMooParallel
What it achieves?
- It works like magic in parallelizing a piece of code.
- Using this design pattern one can embed highly efficient parallel pieces of code in their methods.
- It completely abstracts all details of java multithreading to the developer.
- It enables getting all exceptions in all threads in a single collection.
- It promotes doing parallelable tasks in multiple threads... i.e. it attracts developer to make his code's execution parallel with very little design change.
Advantages over existing Threads infrastructure
- Serial code and Parallel execution
- Abstraction
- Genericity
- Get all errors in all threads in one collection
- Parallel execution of common code on different objects - Code once, Run concurrently with different objects - Example Delete 'n' objects concurrently
Description
- Define the code to be executed in a separate class.
- Pass a collection of objects to be operated concurrently to design pattern.
- The design pattern starts a thread for every object and executes the code over that object.
- Design pattern collects all exceptions thrown in another collection and returns it.
- Design pattern waits for all threads to complete.
- Design pattern can be extended to use thread pools, or it can execute in single thread.
![](http://www.novell.com/coolsolutions/img/jdp6.gif)
Innovations
- Serial coding and Parallel execution
- Parallel execution of Multiple Object operations Design pattern which is language independent
- Error handling in this design pattern- Get all exceptions in all threads in a single collection
- Manager - Worker design pattern
Extensions
- Can be easily translated to C++ or any other Programming language which supports / needs multi threading.
- Can be improved to use Thread pools to become more efficient.
- Can be used as a precursor to develop more intelligent Programming languages.
- Can be used in any domain where parallelism is needed.
Applications
Currently used in iManager plugins to talk to eDirectory
- eDirectory - Read,Write,Delete,Create objects in all replicas for assured synchronization.
- eDirectory - Delete multiple objects, Read multiple objects ...
Future applications
- EJB ..Update customers all accounts, when a customers telephone number changes...
- Distributed databases - Update the object in all replicas ...
- Any code which can be executed concurrently for better performance. (optionally over different objects).