Write a java program that creates several threads

Assignment Help JAVA Programming
Reference no: EM133432092 , Length: 7 pages

Threads in Java

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).

Reference no: EM133432092

Questions Cloud

How these rules and norms will contribute to buidling : List 3-5 basic rules you would like to create that are geared towards keeping things safe in the classroom and running efficiently and consequences for breaking
How will ms. begay know she is teaching her students : How will Ms. Begay know she is teaching her students everything they need to learn this year? What should Ms. Begay find out about her students before
Describe what a typical day for you has been recently : describe what a typical day for you has been recently. In your answer, be sure to enable the reader to gain a clear picture of what this day is like.
Define the two different types of plagiarism : define the two different types of plagiarism and the consequences/implications of plagiarism both in school and in the workplace. Intentional Plagiarism
Write a java program that creates several threads : Write a Java program that creates several threads - creates the two worker threads, starts them and joins them in the end. After that, the main thread
What are some nations or governments : What are some nations or governments that weren't overthrown because they had a strong leadership?
Discuss role purpose function of a liberal arts education : discuss the role/purpose/function of a liberal arts education (and of the humanities) in our culture/society as described by Flannery in Our Greatest need
Summarize what you think the poem is about : Summarize what you think the poem is about (synthesis) State the THEME of the poem (analysis) Identify at least three (3) poetry devices the poet used
How did the speaker get your attention : How did the speaker get your attention? What strategy(ies) did they use? How did the speaker conclude their speech? Was it successful? Why or why not?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd