LiVe YoUr DrEaM…

Archive for the ‘Technical Stuff’ Category

Problem Statement: Four threads need to add one element each at a time in a shared list. Each Thread will have it’s own list, say, Thread 1 will have list1 similarly Thread 2 will have list2 so on. And all threads will add to the list5.

Order in which they need to add elements: Thread 1 will add one element and after Thread 1, Thread 2 will add one element and after Thread 2, Thread 3 will add one element and after Thread 3, Thread 4 will add one element – and after Thread 4 – again Thread 1 will add one element to list 5 until they add all their elements to list5.

Code for above problem [run]:

 * This program used to demonstrate the Thread co-ordination in which threads
 * will execute their tasks in given order. for example: In below example each
 * thread holds a list of integers and it has to iterate and add the elements
 * from list to shared list. In a below given order – Thread 1 will add one
 * element from it’s list to shared list and then wait. After compilation of
 * Thread 1 – Thread 2 will add one element from it’s list to shared list and
 * then wait. Similarly Thread 3 and Thread 4 will add one element in above
 * mentioned order wait. Once Thread 4 – has done adding element to the shared
 * list, again Thread 1 will start and add the element to the thread in above
 * mentioned order.
 * @author sayedkhadri
 * @version 1.0.0
public class ThreadCoordinationSimulator {
List<Integer> sharedListOfIntegers = new ArrayList<Integer>();
Lock l = new ReentrantLock();
Condition c1 = l.newCondition();
Condition c2 = l.newCondition();
Condition c3 = l.newCondition();
Condition c4 = l.newCondition();
* This method will add an integer to shared list after acquiring the lock
* l, otherwise it will wait till lock is available.
* @param i
*            integer to be added.
public void add(int i) {
public static void main(String[] args) {
             List<Integer> l1 = Arrays.asList(1, 2, 3, 4);
            List<Integer> l2 = Arrays.asList(5, 6, 7, 8);
            List<Integer> l3 = Arrays.asList(9, 10, 11, 12);
            List<Integer> l4 = Arrays.asList(13, 14, 15, 16);
            ThreadCoordinationSimulator tester = new ThreadCoordinationSimulator();
            new WorkerForStoringIntegers(l1, tester.l, tester.c4, tester.c1, tester, “Thread 1”).start();
            new WorkerForStoringIntegers(l2, tester.l, tester.c1, tester.c2, tester, “Thread 2”).start();
            new WorkerForStoringIntegers(l3, tester.l, tester.c2, tester.c3, tester, “Thread 3”).start();
            new WorkerForStoringIntegers(l4, tester.l, tester.c3, tester.c4, tester, “Thread 4”).start();
try {
} catch (Exception e) {
The Worker Thread.

* @author sayedkhadri
* @version 1.0.0
public class WorkerForStoringIntegers extends Thread {
Lock lock = null;
Condition waitForCondition = null;
Condition notifyCondition = null;
List<Integer> listOfIntegers = new ArrayList<Integer>();
ThreadCoordinationSimulator tester = null;

public WorkerForStoringIntegers(List<Integer> listOfIntegers, Lock lock, Condition waitForCondtion, Condition notifyCondtion, ThreadCoordinationSimulator tester, String threadName) {

this.lock = lock;
this.waitForCondition = waitForCondtion;
this.notifyCondition = notifyCondtion;
this.listOfIntegers = listOfIntegers;
this.tester = tester;


public void run() {


try {

for (Integer i : listOfIntegers) {
System.out.println(Thread.currentThread().getName() + ” Adding Element: ” + i + ” to shared list.”);
notifyCondition.signalAll();//once addition is done, notify the one who is waiting.

waitForCondition.await();//wait till you are notified.

System.out.println(Thread.currentThread().getName() + ” Successfully Completed.”);

} catch (Exception e) {



Save and in same package and run

Let me know your views on this.


Nokia N73 ME.. It’s not just the phone, it’s a multimedia device with lots of features. Last year I purchased it and still I am using it. It has Great 3.2 Mega Pixels camera with Carl Zeiss optics which will give you the great pics.
It also has excellent sound quality with stereo speakers.
It will come with 1 GB memory card, but I upgraded it to 2GB.
It has symbian s60 platform. It has two browsers
1. Service Browser.
2. Web Browser.

Nokia N73 Me

Nokia N73 Me

Nokia N73 Me

Technical Specification :
* Weight: 116 g
* Height: 110 mm
* Width: 49 mm

* Black or Latte

* Up to 40 MB* internal dynamic memory.
* Support for miniSD memory card upto 2GB.

* 3.2 Mega Pixel with Carl Zeiss Lences

* Digital music player with stereo headsets.
* Visual Radio

My Nokia ~ My World.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 63 other followers


  • 48,830 times

My Tweets (Click to follow me)

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

Indi Rank



Visitors Locations