63 169
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #66998 in Java | JSP | JSF for Gene Moore

Question #66998
Provide a programming example in which multithreading does not provide better performance than a single-threaded solution
Expert's answer
Example below shows, that multi-threading programs not always have performance benefit.

For example simple tasks(like iterating 100 elements) will not give better performance, but will use more CPU and RAM memory for it

Example:

import java.util.Random;

public class Main {

public static void main(String[] args) {
int[] arr = new int[100];



new Thread(() -> {

for (int i = 0; i < arr.length; i++) {
arr[i] = new Random().nextInt();
System.out.println("Thread " + arr[i]);
}
}).start();
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions