Write a program that launches 1,000 threads. Each thread adds 1 to a variable sum that initially is 0. You need to pass sum by reference to each thread. In order to pass it by reference, define an Integer wrapper object to hold sum. Run the program with and without synchronization to see its effect. Submit the code of the program and your comments on the execution of the program.

Answers

Answer 1

Answer:

Following are the code to the given question:

import java.util.concurrent.*; //import package

public class Threads //defining a class Threads

{

private Integer s = new Integer(0);//defining Integer class object

public synchronized static void main(String[] args)//defining main method  

{

Threads t = new Threads();//defining threads class object

System.out.println("What is sum ?" + t.s);//print value with message

}

Threads()//defining default constructor

{

ExecutorService exe = Executors.newFixedThreadPool(1000);//defining ExecutorService class object

System.out.println("With SYNCHRONIZATION........");//print message

for(int i = 1; i <= 1000; i++)//defining a for loop

{

exe.execute(new SumTask2());//calling execute method

System.out.println("At Thread " + i +" Sum= " + s + " , ");//print message with value

}

exe.shutdown();//calling shutdown method

while(!exe.isTerminated())//defining while loop that calls isTerminated method

{

}

}

class SumTask2 implements Runnable//calling SumTask2 that inherits Runnable class

{

public synchronized void run()//defining method run

{

int value = s.intValue() + 1;//defining variable value that calls intvalue which is increment by 1

s = new Integer(value);//use s to hold value

}

}

}

Output:

Please find the attached file.

Explanation:

In this code, a Threads class is defined in which an integer class object and the main method is declared that creates the Threads class object and calls its values.

Outside the method, the default constructor is declared that creates the "ExecutorService" and prints its message, and use a for loop that calls execute method which prints its value with the message.

In the class, a while loop is declared that calls "isTerminated" method, and outside the class "SumTask2" that inherits Runnable class and defined the run method and define a variable "value" that calls "intvalue" method which is increment by 1 and define s variable that holds method value.

Write A Program That Launches 1,000 Threads. Each Thread Adds 1 To A Variable Sum That Initially Is 0.

Related Questions

I need it in code please (python)

Answers

python coded) pythooonn

Answer:

def main():

 n = int(input("Enter a number to find its sum! "))

 sum = int((n*(n+1)) / 2)

 print(str(sum))

main()

Explanation:

Here is some code I quickly came up with, you can rehash it for your liking.

I basically took this formula and translated it into python code on line 3. Make sure you use paratheses correctly when translating forumlas or any equation, Order of Operations is everything.

Lmk if this helped!


Which of the following is not a data visualization technique?

Answers

Answer:

Normalization

Explanation:

From the options given :

Boxplot is a data visualization techniqye used for representing numerical data in the form of a box such that it adequately conveys the five number summary if the dataset which are the minimum, maximum, lower quartile, median and upper quartile, it also depicts the presence of outlines.

Scatter plot are used depict the relationship between two variables on the x and y axis of a graph. Each point is a representation of the (x, y) value pairs of the observation.

Tag clouds are usually used to represent word, metatdata and other free form text using different colors and font sizes to give information about the data.

Normalization is the odd option out as it is used to restructure data in other to promote integrity of data.

Write down the short history of COMPUTER? ​

Answers

Answer:

Charles Babbage, an English mechanical engineer and polymath, originated the concept of a programmable computer. Considered the "father of the computer",he conceptualized and invented the first mechanical computer in the early 19th century.

explain the elements of structured cabling systems​

Answers

Answer:

From this article, we can know that a structured cabling system consists of six important components. They are horizontal cabling, backbone cabling, work area, telecommunications closet, equipment room and entrance facility.

dismiss information I have here and hope you like it and hope you will get this answer helpful and give me the thankyou reactions

Write a program that uses the function strcmp() to compare two strings input by the user. The program should state whether the first string is less than, equal to, or greater than the second string7. Write a program that uses the function strcmp() to compare two strings input by the user. The program should state whether the first string is less than, equal to, or greater than the second string

Answers

user_str1 = str ( input ("Please enter a phrase: "))

user_str2 = str ( input("Please enter a second phrase: "))

def strcmp (word):

user_in1 = int (len(user_str1))

user_in2 = int (len(user_str2))

if user_in1 > user_in2:

return "Your first phrase is longer"

elif user_in1 < user_in2:

return "Your second phrase is longer"

else:

return "Your phrases are of equal length"

Help Pls
I need about 5 advantages of E-learning​

Answers

Answer:

Explanation:

E-learning saves time and money. With online learning, your learners can access content anywhere and anytime. ...

E-learning leads to better retention. ...

E-learning is consistent. ...

E-learning is scalable. ...

E-learning offers personalization.

Answer:

E- learning saves time and money

E-learning makes work easier and faster

E- learning is convenient

E- learning is consistent

E- learning is scalable

Explanation:

when you learn using the internet, you save a lot of time by just typing and not searching through books

convert decimal number into binary numbers (265)10

Answers

Answer:

HELLOOOO

Alr lets start with steps by dividing by 2 again and againn..

265 / 2 = 132 ( rem = 1 )

132 / 2 = 66 ( rem = 0 )

66/2 = 33 ( rem = 0 )

33/2 = 16 ( rem = 1 )

16/2 = 8 ( rem = 0 )

8/2 = 4 ( rem = 0 )

4/2 = 2 ( rem = 0 )

2/2 = 1 ( rem = 0 )

1/2 = 0 ( rem = 1 )

now write all the remainders from bottom to up

100001001

is ur ans :)))

various gabs in the digital divide​

Answers

Answer:

factors such as low literacy and income level Geographical restriction lack of motivation motivation of the technology lack of motivation to use technology and digital illiteracy and contribute to the digital device

Genevieve is a student who attends classes at a campus downtown. She likes to study in the college's coffee shop, where she often accesses the Internet through the college's wireless network. Which network type is Genevieve using

Answers

Answer:

I'll let you make an educated guess off of this info! You always retain info better making an inference on a subject that you are having trouble with!

Explanation:

There are four types of wireless networks -- wireless local area networks, wireless metropolitan area networks, wireless personal area networks and wireless wide area networks -- each with its own function.

wireless local area network

A wireless local area network (WLAN) is a wireless distribution method for two or more devices. WLANs use high-frequency radio waves and often include an access point to the Internet. A WLAN allows users to move around the coverage area, often a home or small office, while maintaining a network connection.

wireless metropolitan area network

A metropolitan area network (MAN) is a computer network that connects computers within a metropolitan area, which could be a single large city, multiple cities and towns, or any given large area with multiple buildings. A MAN is larger than a local area network (LAN) but smaller than a wide area network (WAN).

wireless personal area network

A PAN provides data transmission among devices such as computers, smartphones, tablets and personal digital assistants. PANs can be used for communication among the personal devices themselves, or for connecting to a higher level network and the Internet where one master device takes up the role as gateway.

wireless wide area network

Wireless wide area network (WWAN), is a form of wireless network. ... WWAN connectivity allows a user with a laptop and a WWAN card to surf the web, check email, or connect to a virtual private network (VPN) from anywhere within the regional boundaries of cellular service.

I hope this helped!!

shania

The network type Genevieve uses is a wireless local area network.

What is a wireless local area network?

A wireless local area network (WLAN) exists as a wireless distribution procedure for two or more devices. WLANs utilize high-frequency radio waves and often contain an access issue to the Internet. A WLAN permits users to move around the coverage area, often a house or small office, while preserving a network connection.

Therefore, the correct answer is option (a) LAN.

Complete questions:

Genevieve is a student who attends classes at a campus downtown. She likes to study in the college's coffee shop, where she often accesses the Internet through the college's wireless network. Which network type is Genevieve using

(a) LAN

(b) MAN

(c) PAN

(d) WAN

To learn more about wireless local area networks refer to:

https://brainly.com/question/8985345

#SPJ2

what is a computer memory

Answers

Answer:

it is your answer

Explanation:

it is the storage space where data is kept.

Ellen is working on a form in Access and clicks on the Design tab in the Form Design Tools section. Ellen then clicks on the Controls button and clicks the Label icon. What is Ellen most likely doing to the form?
A.adding a title
B.adding an existing field
C.changing the anchoring setting
D.changing the font of a label

Answers

Answer:

D. changing the font of a label

A light rag is striking the surface of earth. Which factor would make the light ray more likely to be absorbed than reflected?

Answers

Answer:

The answer is D.

Explanation:

because the other answers doesn't make sense.

Write a program to print all odd numbers between 20 and 50(Qbasic)​

Answers


Source Code:

total = 0

FOR x = 20 TO 50 STEP 2
total = total + x
NEXT x

PRINT "Total=";total

discribe two ways you can zoom in and out from an image

Answers

How to zoom in: u get any two of ur fingers and instead of going inward like ur tryna pop a zit, you go out

How to zoom out: pretend like ur popping pimples on ur phone/device screen

Write steps to Delete data from ‘Datagridview’

Answers

Explanation:

private void btnDelete_Click(object sender, EventArgs e)

{

if (this.dataGridView1.SelectedRows.Count > 0)

{

dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);

}

}

Transitive spread refers to the effect of the original things transmitted to the associate things through the material, energy or information.

a. True
b. False

Answers

A is the correct answer

For the following scenario, indicate whether the action is a good practice or bad practice to safeguard your personally identifiable information.
Marina's personal computer requires a password to get access.

Answers

Answer:

This is most definitely a good practice to safeguard personal information. This way, people wouldn't be able to access her computer easily, since it requires a code that only she would know. of course, there is the possibility that someone can just guess or hack into her computer, but that's why computers usually have you create a unique code that consists of uppercases, lowercases, numbers, special characters, etc which would be difficult to guess. it's a good protection for anyone who wants to safely keep their personal information from everyone else.

Suppose a program written in language L1 must be executed on a machine running a program running in language L0. What important operation must take place

Answers

Question Completion with Options:

a. Translation of the entire L1 program into L0 code

b. Translation of the L0 program into L1 code

c. Creation of a language L3 that interprets L0 instructions

d. Interpretation of each L1 statement using L0 code as the L1 program is running.

Answer:

The important operations that must take place in this scenario are:

a. Translation of the entire L1 program into L0 code

d. Interpretation of each L1 statement using L0 code as the L1 program is running.

Explanation:

Translation enables decoding to take place.  This means that the L1 program is decoded into a language that the L0 program can understand and execute.  Without this translation, the higher level language of L1 will not be understood by the machine language of the L0 programs.  Translation of a code creates a shared understanding, thereby easing program execution.  Code translation is simultaneously accompanied by interpretation.

Write a Python program stored in a file q1.py to play Rock-Paper-Scissors. In this game, two players count aloud to three, swinging their hand in a fist each time. When both players say three, the players throw one of three gestures: Rock beats scissors Scissors beats paper Paper beats rock Your task is to have a user play Rock-Paper-Scissors against a computer opponent that randomly picks a throw. You will ask the user how many points are required to win the game. The Rock-Paper-Scissors game is composed of rounds, where the winner of a round scores a single point. The user and computer play the game until the desired number of points to win the game is reached. Note: Within a round, if there is a tie (i.e., the user picks the same throw as the computer), prompt the user to throw again and generate a new throw for the computer. The computer and user continue throwing until there is a winner for the round.

Answers

Answer:

The program is as follows:

import random

print("Rock\nPaper\nScissors")

points = int(input("Points to win the game: "))

player_point = 0; computer_point = 0

while player_point != points and computer_point != points:

   computer = random.choice(['Rock', 'Paper', 'Scissors'])

   player = input('Choose: ')

   if player == computer:

       print('A tie - Both players chose '+player)

   elif (player.lower() == "Rock".lower() and computer.lower() == "Scissors".lower()) or (player.lower() == "Paper".lower() and computer.lower() == "Rock".lower()) or (player == "Scissors" and computer.lower() == "Paper".lower()):

       print('Player won! '+player +' beats '+computer)

       player_point+=1

   else:

       print('Computer won! '+computer+' beats '+player)

       computer_point+=1

print("Player:",player_point)

print("Computer:",computer_point)

Explanation:

This imports the random module

import random

This prints the three possible selections

print("Rock\nPaper\nScissors")

This gets input for the number of points to win

points = int(input("Points to win the game: "))

This initializes the player and the computer point to 0

player_point = 0; computer_point = 0

The following loop is repeated until the player or the computer gets to the winning point

while player_point != points and computer_point != points:

The computer makes selection

   computer = random.choice(['Rock', 'Paper', 'Scissors'])

The player enters his selection

   player = input('Choose: ')

If both selections are the same, then there is a tie

   if player == computer:

       print('A tie - Both players chose '+player)

If otherwise, further comparison is made

   elif (player.lower() == "Rock".lower() and computer.lower() == "Scissors".lower()) or (player.lower() == "Paper".lower() and computer.lower() == "Rock".lower()) or (player == "Scissors" and computer.lower() == "Paper".lower()):

If the player wins, then the player's point is incremented by 1

       print('Player won! '+player +' beats '+computer)

       player_point+=1

If the computer wins, then the computer's point is incremented by 1

   else:

       print('Computer won! '+computer+' beats '+player)

       computer_point+=1

At the end of the game, the player's and the computer's points are printed

print("Player:",player_point)

print("Computer:",computer_point)

You are going to purchase (2) items from an online store.
If you spend $100 or more, you will get a 10% discount on your total purchase.
If you spend between $50 and $100, you will get a 5% discount on your total purchase.
If you spend less than $50, you will get no discount.
Givens:
Cost of First Item (in $)
Cost of Second Item (in $)
Result To Print Out:
"Your total purchase is $X." or "Your total purchase is $X, which includes your X% discount."

Answers

Answer:

Code:-

using System;

using System.Collections.Generic;

class MainClass {

public static void Main (string[] args) {

int Val1,Val2,total;

string input;

double overall;

Console.Write("Cost of First Item (in $)");

      input = Console.ReadLine();

Val1 = Convert.ToInt32(input);

Console.Write("Cost of Second Item (in $)");

      input = Console.ReadLine();

Val2 = Convert.ToInt32(input);

total=Val1+Val2;

if (total >= 100)

{

overall=.9*total;

Console.WriteLine("Your total purchase is $"+overall);

}

else if (total >= 50 & total < 100)

{

overall=.95*total;

Console.WriteLine("Your total purchase is $"+overall);

}  

else

{

Console.WriteLine("Your total purchase is $"+total);

}  

}

}

Output:

The development of the modern computer system has been evolutionary. Discuss this phenomenon and further discuss how current trends in computing would impact future computer systems development.

Answers

Explanation:

With the great advances in computer systems today it is possible that we can connect and interact with people who are on the other side of the planet, we can study virtually without having to attend a university or school in person, we can even work from our own homes without having to travel to our workplace, which allows us to reduce transportation costs and time.

The above benefits have been possible thanks to the evolution of computer systems.But just as the evolution of computer systems brings great benefits, it also carries great risks for the future, in recent years there has been a considerable increase in cyber attacks, therefore it is necessary an advanced cybersecurity system that allows to quickly control and protect from external threats to organizations; As well as it is necessary to emphasize training in computer systems for people of all educational levels so that they are prepared and can give proper use to computer systems and thus also learn to protect themselves from cyber fraud.

disadvantage of monolithic programming​

Answers

Answer:

=Tight coupling between components, as everything is in one application.

=Less reusability.

=Large code base; tough for developers and QA to understand the code and business knowledge.

=Less Scalable.

=Does not follow SRP (Single Responsibility Principle)

=More deployment and restart times.

1. Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value. Prompt the user for an input value and try the Math.sqrt() method on it. The application either displays the square root or catches the thrown Exception and displays an appropriate message. Save the file as SqrtException.java.
2. Create a ProductException class whose constructor receives a String that
consists of a product number and price. Save the file as ProductException.java.
Create a Product class with two fields, productNum and price. The Product
constructor requires values for both fields. Upon construction, throw a
ProductException if the product number does not consist of three digits, if the
price is less than $0.01, or if the price is over $1,000. Save the class as Product.java.
Write an application that establishes at least four Product objects with valid and invalid values. Display an appropriate message when a Product object is created
successfully and when one is not. Save the file as ThrowProductException.java.

Answers

Answer:

Hence the answer is given as follows,

How many cost units are spent in the entire process of performing 40 consecutive append operations on an empty array which starts out at capacity 5, assuming that the array will grow by a constant 2 spaces each time a new item is added to an already full dynamic array

Answers

Answer:

Explanation:

260 cost units, Big O(n) complexity for a push

what is 1 st genaration of computer ​

Answers

Explanation:

The period of first generation computer was from 1946-1959 AD .The computers of first generation used vacuum tubes as the basic components for memory and circuitry for CPU ( Central Processing Unit).These tubes, like electric bulbs, produced a lot of heat and were prone to frequent fusing of the installation.

Hope it helps...............

How can the system administrator give the executive assistant the ability to view, edit, and transfer ownership of all records, but not allow her to delete the records

Answers

i don’t think that’s possible. giving control to edit records also means giving control to delete them. maybe discuss before hand to build trust and understanding or duplicate the records in case she does delete them

Select the pseudo-code that corresponds to the following assembly code. Assume that the variables a, b, c, and d are initialized elsewhere in the program. You may want to review the usage of EAX, AH, and AL (IA32 registers). Also recall that the inequality a > b is equivalent to b < a. i.e. If A is greater than B, that's equivalent to saying that B is less than A.
.data
; General purpose variables
a DWORD ?
b DWORD ?
c BYTE ?
d BYTE ?
upperLevel DWORD 18
lowerLevel DWORD 3
; Strings
yes BYTE "Yes",0
no BYTE "No",0
maybe BYTE "Maybe",0
code
main PROC
mov eax, 1
cmp AH, c
jg option1
jmp option3
option1:
mov edx, OFFSET yes
call WriteString
jmp endOfProgram
option2:
mov edx, OFFSET no
call WriteString
jmp endOfProgram
option3:
mov edx, OFFSET maybe
call WriteString
endOfProgram:
exit
main ENDP
END main
a) if (c > 0)
print (yes);
else
print (maybe);
b) if (c < 0)
print (yes);
else
print (maybe);
c) if (c < 1)
print (yes);
else
print (maybe);
d) if (c > 1)
print (yes);
else
print (maybe);

Answers

Answer:

ae

Explanation:

The pseudo-code that corresponds to the given assembly code is:

b) if (c < 0)

print (yes);

else

print (maybe);

What is the pseudo-code

In assembly code, the command cmp AH, c checks if the high byte of the EAX register (AH) has the same value as the variable c. Then, if the value in AH is more than the value in c, the instruction jg option1 will move to option1.

Therefore, In the pseudo-code, one can check if c is smaller than 0. If it happens, we say "yes". If not, we say "maybe"

Read more about   pseudo-code here:

https://brainly.com/question/24953880

#SPJ2

Which is the first computer brought in nepal for the census of 2028 B.S​

Answers

Answer:

The first computer brought in Nepal was IBM 1401 which was brought by the Nepal government in lease (1 lakh 25 thousands per month) for the population census of 1972 AD (2028 BS). It took 1 year 7 months and 15 days to complete census of 1crore 12.5 lakhs population.

Many Java programs that you create will receive and process user input. In order to ensure that user input is accurate, you will need to use input validation and exception handling.

a. True
b. False

Answers

Answer: True

Explanation: True

Explain how communication has helped to the staff in organization to reach their maximum delivery of service with efficience and effectiveness ​

Answers

Answer:

i don't know

Explanation:

Other Questions
Exponential and Alogarithmic Functions - Alegebra question In music, what does BPM stand for?A. Better position musicB. Beats per masterC. Beats per malletD. Beats per minuteAnswer is D!!!!! .-A qu se refiere Roldan cuando exclama "pero esa mercanca, solo habr de obtenerla por el acero"? porfi necesito ayuda cry This New Deal program sought to improve the conditions of poor landowning farmers and sharecroppers. a.Civil Works Administration b.Farm Security Administration c.National Industrial Recovery Act d.Federal Security Agency Why is the date of the munson report important The great gatsby Analyze the following quotation: In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. "Whenever you feel like criticizing any one," he told me, "just remember that all the people in this world haven't had the advantages that you've had."Helpppp The model of competitive markets relies on these three core assumptions: 1. There must be many buyers and sellers-a few players can't dominate the market. 2. Firms must produce an identical product-buyers must regard all sellers' products as equivalent. 3. Firms and resources must be fully mobile, allowing for free entry into and exit from the industry. The first two conditions imply that all consumers and firms are price takers. While the third is not necessary for price-taking behavior, assume for this problem that a market cannot maintain competition in the long run without free entry.Identify whether or not each of the following scenarios describes a competitive market, along with the correct explanation of why or why not. Scenario Competitive1. Several stores in the mall sell hooded sweatshirts. Each store's sweatshirts reflect the style of that particular store. Additionally, some stores use higher-quality cotton than others, which is reflected in the apparel's prices. 2. In a small town, there are two providers of broadband Internet access: a cable company and the phone company. The Internet access offered by both providers is of the same speed. 3. There are hundreds of high school students in need of algebra tutoring services in Dallas. 4. Dozens of companies offer tutoring services, and the parents who seek out tutors view the quality of the tutoring at the different companies to be largely the same. 5. The government has granted a patent to a pharmaceutical company for an experimental AIDS drug. That company is the only firm permitted to sell the drug. Which is true if energy in ecosystem PLEASE I NEED THIS NOW 50 POINTS Write your answer as a functionAndy is wrapping gifts for his family. He ties 25 inches of ribbon around each gift. Which function gives the relationship between the number ofgifts (g) and the length of ribbon used (9)?The function representing the relationship between the length of ribbon and the number of gifts is ? The first excited state of a particular atom in a gas is 6.1 eV above the ground state. A moving electron collides with one of these atoms, and excites the atom to its first excited state. Immediately after the collision the kinetic energy of the electron is 3.2 eV. What was the kinetic energy of the electron just before the collision A company has these balances as of december 31 cash 20000 fixed assets 35000 accumulated depreciation 20000 accounts payable 5000 what are the total assets? Why will it be easier for the United States and Western Europe to deal with climate change than countries in Africa? Which type of medications are manufactured as an antigen against the disease-causing bacteria or virus and then administered to healthy individuals to produceadaptive immune response?Chemotherapy drugsImmune-modulatorsVaccinesAlkylating agentsPlease help. Thx Marlow Company purchased a point of sale system on January 1 for $6,500. This system has a useful life of 5 years and a salvage value of $950. What would be the depreciation expense for the second year of its useful life using the double-declining-balance method nonsense= reported[ EPP 4] by: johnglenleemahusay 190 students sit in an auditorium listening to a physics lecture. Because they are thinking hard, each is using 125 W of metabolic power, slightly more than they would use at rest. An air conditioner with a COP of 5.0 is being used to keep the room at a constant temperature. What minimum electric power must be used to operate the air conditioner? Please answer fast!!!!!Explain the steps you would use to solve the equation. Find the solution.8^2x=4096 Which of the following statements can correctly be made about illness? 10 3(2a 1) = 3a + 1 Chang Industries has 2,800 defective units of product that have already cost $14.80 each to produce. A salvage company will purchase the defective units as they are for $5.80 each. Chang's production manager reports that the defects can be corrected for $5.20 per unit, enabling them to be sold at their regular market price of $22.60. The incremental income or loss on reworking the units is: