Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Documentation – Laboratory 6

Implement the above Concurrent Countering example in Java


After reading the documentation referenced in the laboratory, I started to implement the example in
the laboratory and everything worked fine, the output as expected was 20000000.

Implement the CountDownLatch example in the slides


Below is the implementation with the Count Down Latch

Implement the CyclicBarrier example in the slides


To implement this example, I used three class which are showed below:
Cyclic Barrier Class

Party Class
Main Class

Check what happens if for point one we do the following changes:


1. The used “Semaphore s” variable is no longer static.
The program output changes because being no longer static it will be accessed only by thread p.
2. The “n” variable is no longer static
N will now show 10000000 because N is different now for every thread, so N it’s not shared
between the two thread like in the original example.
3. You acquire before the “for” loop
The result has changed again and it’s showing less than the normal result (20000000).
4. You don’t release or release after the “for” loop
The output will be 2000000.

You might also like