Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is a Java programs you will write a Thread class (can be a Thread subclass or Runnable interface implementer) which will be responsible

This program is a Java programs you will write a Thread class (can be a Thread subclass or Runnable interface implementer) which will be responsible in fining the number of prime numbers in a given range.

Program will require you to write a class which will receive a range of value and it will count the number of primes in that range. It should also return the amount of time it took to calculate the count. Time can be measured as the difference to two calls to System.nanoTime static method. The exact number of threads in your program should be variable between one to many. The number of threads can be a constant parameter t in your program. The program should then be able to allocate the proper ranges to the threads. The range for prime calculation should be from 3 to n. If n = 5,000,000 and t = 2, then thread 1 gets [3 - 2,500,000] and thread 2 gets [2,500,001 -5,000,000]. If n = 5,000,000 and t = 3, then thread 1 gets [3-1,666,666] and thread 2 gets [1,666,667-3,333,333] and thread3 gets [3,333,334-5,000,000], etc.

Specific Instructions:

A sample output of Program 1is shown below.

----------run----------

# Threads = 1

Thread #1 Prime Count = 348512

# Seconds Used = 9.795684926

Total Prime Count = 348512

----------run----------

# Threads = 2

Thread #1 Prime Count = 183071

# Seconds Used = 7.62562728

Thread #2 Prime Count = 165441

# Seconds Used = 9.353472019

Total Prime Count = 348512

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Find b and c so that y = 19c2 + bc + c has vertex (8, 10). b

Answered: 1 week ago

Question

LO2 Explain the major laws governing employee compensation.

Answered: 1 week ago