Purpose To review threads in Java. Threading Divisors Directions and Example: A divisor is a number that evenly divides another number. For example, the number 12 has six divisors: 1, 2, 3, 4, 6 and 12. Download the starting code from the Pilot drop box. This code figures out which number between 1 and 100000 has the greatest number of divisors (spoiler alert: it's 83,160 which has 128 divisors). This code is inefficient, because it computes the number of divisors for each integer between 1 and 100000 one after the other. Your task is to modify the code so that it computes these values in parallel and then determines which one is greatest after all of the threads have finished executing. The output of the code will be the same as before, but the time it takes to run will be lower.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In java pls!

here is some starter code for this problem:

public class ThreadingDivisors {

    public static void main(String[] args) {

        long start = System.currentTimeMillis();
       
        int maxDivisors = 0;
        int answer = 0;
       
        for (int n=1; n<100000; n++) {
            int divisors = getNumDivisors(n);
            if (divisors > maxDivisors) {
                maxDivisors = divisors;
                answer = n;
            }
        }
       
        System.out.println(answer + " has the most divisors (" +
                maxDivisors + ")");
       
        long end = System.currentTimeMillis();
        System.out.println(end - start + " milliseconds");
    }

   
    public static int getNumDivisors(int n) {
        int numDivisors = 0;
        for (int i=1; i<=n; i++) {
            if (n % i == 0) {
                numDivisors++;
            }
        }
        return numDivisors;
    }
}
Purpose
To review threads in Java.
Threading Divisors
Directions and Example:
A divisor is a number that evenly divides another number. For example, the number 12 has six divisors:
1, 2, 3, 4, 6 and 12.
Download the starting code from the Pilot drop box. This code figures out which number between 1 and
100000 has the greatest number of divisors (spoiler alert: it's 83,160 which has 128 divisors). This code
is inefficient, because it computes the number of divisors for each integer between 1 and 100000 one
after the other. Your task is to modify the code so that it computes these values in parallel and then
determines which one is greatest after all of the threads have finished executing. The output of the code
will be the same as before, but the time it takes to run will be lower.
Transcribed Image Text:Purpose To review threads in Java. Threading Divisors Directions and Example: A divisor is a number that evenly divides another number. For example, the number 12 has six divisors: 1, 2, 3, 4, 6 and 12. Download the starting code from the Pilot drop box. This code figures out which number between 1 and 100000 has the greatest number of divisors (spoiler alert: it's 83,160 which has 128 divisors). This code is inefficient, because it computes the number of divisors for each integer between 1 and 100000 one after the other. Your task is to modify the code so that it computes these values in parallel and then determines which one is greatest after all of the threads have finished executing. The output of the code will be the same as before, but the time it takes to run will be lower.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education