Answer to Question #66998 in Java | JSP | JSF for Gene Moore
Provide a programming example in which multithreading does not provide better performance than a single-threaded solution
1
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!
Learn more about our help with Assignments:
JavaJSPJSF
Comments
Leave a comment