Write a Java program that creates several threads, according to the following scenario: The initial...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a Java program that creates several threads, according to the following scenario: • The initial thread will be called the main thread (M) • The main thread (M) creates and starts two worker threads; each worker thread will work on its task • The main thread (M) joins the two worker threads in the end and computes the final result The goal of this program is to find all the Vampire numbers in the interval [100000, 999999]. To achieve this goal we will scan all the integer numbers from 100000 to 999999 and for each of these numbers we must perform a test to verify if that number is a Vampire number or not. In order to solve this problem faster, (assuming we have at least two processors on our system) we will divide the work between the two worker threads: on worker will scan and verify all the even numbers and the other worker will scan and verify all the odd numbers in the interval. More precisely, the following list describes the behavior of each thread: 1. The main thread (M) creates the two worker threads, starts them and joins them in the end. After that, the main thread will compute and display the TOTAL number of Vampire numbers found in the interval [100000, 999999] as "The TOTAL number of Vampire numbers found is: ..." (the ellipsis stand for the actual number) 2. The first worker will scan and verify all the even numbers in the interval [100000, 999999]; whenever a new Vampire number is found, it will be displayed like this: "First worker found: ..." (the ellipsis stand for the actual number); a counter will be incremented every time a new Vampire number was found, and in the end the total number of Vampire numbers found will be displayed: "First worker found ... Vampire numbers" (the ellipsis stand for the actual number) 3. The second worker will scan and verify all the odd numbers in the interval [100000, 999999]; whenever a new Vampire number is found, it will be displayed like this: "Second worker found: ..." (the ellipsis stand for the actual number); a counter will be incremented every time a new Vampire number was found, and in the end the total number of Vampire numbers found will be displayed: "Second worker found ... Vampire numbers" (the ellipsis stand for the actual number) HINTS: The Vampire numbers are described in detail here: https://en.wikipedia.org/wiki/Vampire_number In the end, the worker threads must communicate their counters to the main thread, in order to compute and display the TOTAL number of Vampire numbers in the interval Work on your computer or online using https://replit.com DELIVERABLES: The source code for the Java program, stored in the text file "hw3.java" A screenshot showing the final results of your program's execution, stored in a graphic file like "hw3.png" or "hw3.gif" or "hw3.pdf", etc. E Write a Java program that creates several threads, according to the following scenario: • The initial thread will be called the main thread (M) • The main thread (M) creates and starts two worker threads; each worker thread will work on its task • The main thread (M) joins the two worker threads in the end and computes the final result The goal of this program is to find all the Vampire numbers in the interval [100000, 999999]. To achieve this goal we will scan all the integer numbers from 100000 to 999999 and for each of these numbers we must perform a test to verify if that number is a Vampire number or not. In order to solve this problem faster, (assuming we have at least two processors on our system) we will divide the work between the two worker threads: on worker will scan and verify all the even numbers and the other worker will scan and verify all the odd numbers in the interval. More precisely, the following list describes the behavior of each thread: 1. The main thread (M) creates the two worker threads, starts them and joins them in the end. After that, the main thread will compute and display the TOTAL number of Vampire numbers found in the interval [100000, 999999] as "The TOTAL number of Vampire numbers found is: ..." (the ellipsis stand for the actual number) 2. The first worker will scan and verify all the even numbers in the interval [100000, 999999]; whenever a new Vampire number is found, it will be displayed like this: "First worker found: ..." (the ellipsis stand for the actual number); a counter will be incremented every time a new Vampire number was found, and in the end the total number of Vampire numbers found will be displayed: "First worker found ... Vampire numbers" (the ellipsis stand for the actual number) 3. The second worker will scan and verify all the odd numbers in the interval [100000, 999999]; whenever a new Vampire number is found, it will be displayed like this: "Second worker found: ..." (the ellipsis stand for the actual number); a counter will be incremented every time a new Vampire number was found, and in the end the total number of Vampire numbers found will be displayed: "Second worker found ... Vampire numbers" (the ellipsis stand for the actual number) HINTS: The Vampire numbers are described in detail here: https://en.wikipedia.org/wiki/Vampire_number In the end, the worker threads must communicate their counters to the main thread, in order to compute and display the TOTAL number of Vampire numbers in the interval Work on your computer or online using https://replit.com DELIVERABLES: The source code for the Java program, stored in the text file "hw3.java" A screenshot showing the final results of your program's execution, stored in a graphic file like "hw3.png" or "hw3.gif" or "hw3.pdf", etc. E
Expert Answer:
Answer rating: 100% (QA)
Sure heres a Java program that implements the scenario you described using threads t... View the full answer
Related Book For
Operating Systems Internals and Design Principles
ISBN: 978-0133805918
8th edition
Authors: William Stallings
Posted Date:
Students also viewed these programming questions
-
Given y=4x-x, determine the approximate change in y if x changes from I to 1.02.
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The goal of this assignment is to learn about real-world SDLC failures and apply what we've learned about the SDLC to these "cases". I hope that, by doing this, you will not be involved with (or,...
-
How to get a good answer using data and analysis tools in jmp 1 uses the other variables to predict "passion." passion would need to be aggregated into high/low first, and then you can use logistic...
-
A shell-and-tube heat exchanger is to heat 10,000 kg/h of water from 16 to 84C by hot engine oil flowing through the shell. The oil makes a single shell pass, entering at 160C and leaving at 94C,...
-
Assume Bracy's, a retail establishment, wants to capture a 30 percent share of the evening gown market. In order to capture that share, it has determined that the average price of an evening gown...
-
Hi-Cloud, Inc., is a start-up tech company. It is seeking a substantial line of credit from a federally insured commercial bank. Among other questions, the loan application requires disclosure of the...
-
During the current year, the accountant for the Cartwright Corporation recorded numerous transactions in an account labeled Intangibles as follows: Jan. 2 Incorporation fees $17,500 Jan. 10 Legal...
-
Ahmed, a foreign qualified accountant, has recently returned to Pakistan and has joined a newly incorporated company Radium Limited (RL), a subsidiary of a listed company. Ahmed has been entrusted...
-
Kansas Corp., an American company, has a payment of 5 million due to Tuscany Corp. one year from today. At the prevailing spot rate of 0.90 /$, this would cost Kansas $5,555,556, but Kansas faces the...
-
Formative evaluation is to summative evaluation as _______________. A. cost is to benefit B. test is to measurement. C. continuous feedback is to overall effectiveness. D. subjective decision making...
-
A large national MCO recently entered a major Southwestern metropolitan market. The managed care plan anticipated that, with an intensive advertising campaign and sales effort, it would have 75,000...
-
A health club decided to offer a yearly membership. Separate fees were to be charged for nutrition counseling, tennis court usage, and aerobic instruction. How might this organization implement: (a)...
-
How would you array the following organizations in terms of the depth and breadth of their product lines: (a) a solo- practice family practitioner who does not deliver babies, (b) a multispecialty...
-
Give a SQL update statement that raises all prices by ten percent. Invoice Invoice_ Customer Payment Number Number INTEGER INTEGER DECIMAL(10, 2) 11731 3175 0 11732 3176 249.50 11733 3175 0
-
Give a SQL query that lists all line items that are part of invoice number 11731. Invoice Invoice_ Number INTEGER 11731 11732 11733 Customer_ Number INTEGER 3175 3176 3175 Payment DECIMAL (10, 2) 0...
-
3 F2 Which of the following decreases blood pressure? Norepinephrine Antidiuretic hormone Angiotensin II Aldosterone Natriuretic peptides norepinephrine and epinephrine A Moving to another question...
-
Modify the CYK algorithm so that it applies to any CFG, not just those in CNF.
-
What is accomplished by page buffering?
-
When virtualization first appeared in the x86 marketplace, many server vendors were skeptical of the technology and were concerned that consolidation would impact the sales of servers. Instead,...
-
Providing additional bandwidth for virtualization servers initially involved additional network interface cards (NICs) for more network connections. With the advent of increasingly greater network...
-
Harry wants to contribute either \($6,500\) (BT\($)\) to a traditional deductible IRA or \($6,500\) (AT\($)\) to a Roth IRA. His current tax rate is 30% for ordinary income and 15% for capital gains....
-
Rita, a calendar year taxpayer, is an employee of the RST Partnership, which has a June 30 year-end. The partnership pays Rita a salary of 2,500 per month for the period January 1 through June 30,...
-
The XYZ Partnership reports the following items during 2022: Calculate ordinary income (or loss) by completing page 1 of Form 1065, and complete Schedule K (Partners Shares of Income, Credits,...
Study smarter with the SolutionInn App