Skip to main content

Posts

Showing posts from June, 2011

Multi-Threaded Execution Control

In this tutorial I'll explain mechanism to control multiple thread execution sequence. To explain the concept, I'll consider a sample execution scenario where a set of operations execute in sequence, but each operation runs in different threads. Lets consider content download scenario, Login to the Content Server -> Browse Content -> Download Content. 3 Threads will execute each of these operations and these operations are inter dependent and will follow the order, login - browse - download . Let's jump into the implementation, we'll have Synchronized blocks for 3 different functions and we'll do thread execution control using wait()/notifyAll() methods. To determine the order of execution we'll use one variable state which can hold 3 different values- Login , Browse and Download . Synchronization blocks will be locked with a Private Object lock. This is more effective and fail pro