OpenMRS
Multi threading exercises in Java - Java Beginners
You are expected to learn about the multithreading in Java. If you don't about the threads in Java, please search in the Google for these following resources,
- What are threads in Java?
- How to implement multithreading in Java?
Now, you need to run this following simple program with three threads.
- Initialize a variable
sum = 0
- Run a for loop for 10 times. i.e :
for(int x = 0; x < 10; x++)
. Add the valuex
to the valuesum
in each iteration - Print the thread name, and the value as follows :
"Thread : A - value : 45 "
in each iteration - Finally Print the sum from each thread as follows :
"Thread : A - Sum : 45 "
You need to run the above code with at least three threads (name those threads as A,B,C....), and find the output.
Submission Steps
- You should upload the screenshot of the outputs with the java commands.
- Paste your code in to Git Gists, and submit the public URL.
- Comment your observations on the thread executions (atleast 2 points)
Task tags
Students who completed this task
Sumeet kumar, Merlin Osayimwen, Brandon, Shreyster, Krzysztof MizgaĆa, KuZu13, marcin.kowalczyk, ariban900, jwzhang, byte.1, maksi069, kgauld1, Smalec, REDACTED, akshatj01, symt, iperez, vinayakgajjewar, Coding Cook, Aditya, MK, Terence, SphericalPotatoInVacuum, Esha_2003, panda789