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,

  1. What are threads in Java?
  2. How to implement multithreading in Java?

Now, you need to run this following simple program with three threads.

  1. Initialize a variable sum = 0
  2. Run a for loop for 10 times. i.e : for(int x = 0; x < 10; x++) . Add the value x to the value sum in each iteration
  3. Print the thread name, and the value as follows : "Thread : A - value : 45 " in each iteration
  4. 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

  1. You should upload the screenshot of the outputs with the java commands.
  2. Paste your code in to Git Gists, and submit the public URL.
  3. Comment your observations on the thread executions (atleast 2 points)

Task tags

  • threads
  • java

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

Task type

  • code Code
close

2018