Thursday, August 22, 2013

Methods should be called within a sequence


A class foo could have the following three methods.
If a single object of Foo is passed in three threads t1, t2 and t3. The threads calls the methods in the following order.

  • t1 calls f2()
  • t2 calls f3()
  • t3 calls f1()
Then f1() should get executed first and then f2() and then f3(). t1 will wait for the completion of t3, t2 will wait for the completion of t1. Do not use thread joining as there could be any such number of threads at runtime. The output should look like the following, no matter in what order the methods are being called within the threads.
Code
Output

No comments:

Post a Comment