Created by Jerry Wang, last modified on Nov 12, 2014
PRODUCER: PROD2 is running
CONSUMER2 Consumer Thread is running…
Thread: CONSUMER2 Fetch data from linkedQueue… Queue size: 0 – Consumer2 attempts to read from the queue
PRODUCER: PROD3 is running
PRODUCER: PROD1 is running
CONSUMER1 Consumer Thread is running…
Thread: CONSUMER1 Fetch data from linkedQueue… Queue size: 0 – Consumer1 attempts to read from the queue
Thread: PROD2 Procedued data into queue: data:1… – Producer1 produces 1 data
PRODUCER: PROD2 is running
Thread: CONSUMER2 has consumed one data from queue: Data :1 queue Sise: 0 – The CONSUMER2 consumed one data and the queue became empty
Thread: PROD1 Procedued data into queue: data:2… – Thread 1 produces the second data
PRODUCER: PROD1 is running
Thread: CONSUMER1 has consumed one data from queue: Data :2 queue Sise: 0 – CONSUMER1 consumed the second data
Thread: PROD3 Procedued data into queue: data:3… – Producer produces the third number
PRODUCER: PROD3 is running
Thread: CONSUMER2 Fetch data from linkedQueue… queue size: 1
Thread: CONSUMER2 has consumed one data from queue: data:3 queue Sise: 0 – The consumer consumes the third data
Thread: PROD2 Procedued data into queue: data:4… – Producer produces the fourth number: 4
PRODUCER: PROD2 is running
Thread: CONSUMER1 Fetch data from linkedQueue… queue size: 1
Thread: PROD1 Procedued data into queue: data:5… – Producer produces the fifth number: 5
PRODUCER: PROD1 is running
Thread: PROD3 Procedued data into queue: data:6… – Producer produces the sixth number: 6
PRODUCER: PROD3 is running
Thread: CONSUMER1 has consumed one data from queue: data:4 queue sise: 1 – CONSUMER1 consumed 4 and has 5,6 left in the queue.
Consumer1 sees only one element at this point
Thread: CONSUMER2 Fetch data from linkedQueue… Queue size: 2 – consumer2 sees 2 elements 5,6
Thread: PROD2 Procedued data into queue: data:7… 7 after production, there are three elements in the queue 5,6,7
Thread: PROD2 quit from producer thread
Thread: CONSUMER2 has consumed one data from queue: data:5 queue sise: 2-5 after being consumed, there is 6,7 left
Thread: PROD1 Procedued data into queue: data:8… – we have 6,7,8 in our queue
Thread: PROD1 quit from producer thread
Thread: CONSUMER1 Fetch data from linkedQueue… queue size: 2
Thread: CONSUMER1 has consumed one data from queue: data:6 queue sise: 2-6 after being consumed, there is 7,8 left
Thread: PROD3 Procedued data into queue: data:9… -9 gets produced, 7,8,9 in the queue
Thread: PROD3 quit from producer thread
Thread: CONSUMER2 Fetch data from linkedQueue… queue size: 3
Thread: CONSUMER2 has consumed one data from queue: data:7 queue sise: 2 – there is 8,9 left in queue
Thread: CONSUMER1 Fetch data from linkedQueue… queue size: 2
Thread: CONSUMER1 has consumed one data from queue: data:8 queue Sise: 1 – There is 9 left in the queue
Thread: CONSUMER2 Fetch data from linkedQueue… queue size: 1
Thread: CONSUMER2 has consumed one data from queue: data:9 queue Sise: 0 – Queue Is consumed and no producer is running
Thread: CONSUMER1 Fetch data from linkedQueue… queue size: 0
Thread: CONSUMER2 Fetch data from linkedQueue… queue size: 0
Thread: CONSUMER1 Consumer read queue timeout – Exits due to timeout
Thread: CONSUMER1 consumer thread ends
Thread: CONSUMER2 Consumer read queue timeout – Exits due to timeout
Thread: CONSUMER2 consumer thread ends
If you make the read operation timeout for the consumer smaller, say 2 milliseconds,
The consumer can’t wait for the producer to put the data in the queue before timeout exits:
If the time interval of the producer’s production data is shortened, and scenario is that the producer will complete the production of all the data in advance and then the consumers will consume one by one.
git path: Github.com/i042416/con…