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
1
Expert's answer
2017-03-30T09:35:07-0400
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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS