In the Part II of Executor Framework blog post series, I had written about creating cancellable
Runnable task and creating
Runnable task with a timeout with the help of this framework. I had also written about two
submit methods of
ExecutorService, which are used to create asynchronous task.
In the Part I of Executor Framework blog post series, I had written how it can be used to create a single worker thread for sequential execution of tasks and create a thread pool of fixed number of threads. In this blog post, I’m writing about the following uses of Executor framework:
With the introduction of asynchronous methods in EJB 3.1, the clients can now call session bean methods asynchronously using the no-interface, remote or local business views. Prior to EJB 3.1, JMS or Message Driven Beans(MDBs) were used for performing asynchronous tasks. Now with the inclusion of asynchronous methods in session beans in EJB 3.1, the MDB need not be used unless there is really a need for point-to-point or publish-subscribe messaging.
In a Java application, a thread may keep waiting for a long time after executing
Thread.join() or by
take() methods of a BlockingQueue. We also refer such a thread as a blocked thread since it remains blocked until some operation is performed. Sometimes a thread can also be blocked for a certain time by
Thread.sleep(). When a thread is blocked for a long time you may need to take the thread out of the WAITING or TIMED_WAITING state. While writing a Java application, we need to take care that a thread does not remain blocked for too long. The corrective action that needs to be performed in such circumstances depends on the type of task the thread is executing. If the task is cancellable, it is simply aborted and if it is not cancellable then a logic needs to be implemented to enable its execution.
We know you enjoy reading digital business and technology blogs. Well, that's why you are here. Isn't it? We share this love as well. That's why we created a place where our digital professionals from different technology and business teams could come and discuss ideas to foster business transformation through technology, digital philosophy and user centric design.
The views and opinions expressed in this weblog represent that of the author and not those of the employer. e-Zest holds no responsibility for the correctness of it.
e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.