1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
marshall27 [118]
2 years ago
5

(Synchronized threads) Write a program that launches 1000 threads. Each thread adds a random integer (ranging from 1 to 3, inclu

sive) to a variable sum that is initially 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.
Computers and Technology
1 answer:
Goshia [24]2 years ago
4 0

Using the knowledge in computational language in JAVA it is possible to write a code that organizes and synchronizes the programs that will run on the computer.

<h3>Writting the JAVA code as:</h3>

<em>import java.util.concurrent.ExecutorService;</em>

<em>import java.util.concurrent.Executors;</em>

<em>public class Main</em>

<em>{</em>

<em>Integer sum=new Integer(0);</em>

<em>Main(){</em>

<em>ExecutorService e=Executors.newFixedThreadPool(1000);</em>

<em>final Sum s = new Sum();</em>

<em>for(int i=0;i<1000;i++){</em>

<em>e.execute(s);</em>

<em>}</em>

<em>e.shutdown();</em>

<em>while(!e.isTerminated()){</em>

<em>}</em>

<em>System.out.println(sum);</em>

<em>}</em>

<em>public static void main(String[]args){</em>

<em>new Main();</em>

<em>}</em>

<em>class Sum implements Runnable{</em>

<em>public void run() {</em>

<em>m();</em>

<em>}</em>

<em>public void m(){</em>

<em>sum=sum+1;</em>

<em>}</em>

<em>}</em>

<em>}</em>

See more about JAVA at brainly.com/question/12978370

#SPJ1

You might be interested in
What wired channel, commonly used for cable tv, consists of an insulated copper wire wrapped in a solid or braided shield placed
Airida [17]
the answer is A coaxial cable
8 0
3 years ago
Privacy a. is an absolute value so corporate interests cannot be considered when it comes to employee privacy. b. is guaranteed
zmey [24]

Answer:

C. Must be respected if we are to function as complete, self-governing agents.

Explanation:

<em>Privacy</em> is the boundaries that are set up to protect us against unwanted intrusion or interference, and it forms the basis of our interaction with the world.

<em>Privacy laws</em> are set-up to protect individuals from unwanted and unapproved access to privacy by individuals, organizations, and government. This is greatly adhered to in many countries.

To some extent, privacy is considered to overlap with security, because, when private information such as social security number, bank card details, account names, and details, etc. are accessed inappropriately, the individual's security is greatly compromised.

Therefore, privacy must be greatly respected if we are to function as complete, self-governing agents.

8 0
3 years ago
Which type of exception would be detected if you used the conversion command Convert.ToDecimal to try to convert an ampersand?
Anestetic [448]

Answer:

Visual basic

Explanation:

Implicit and Explicit Conversion

4 0
3 years ago
PLS HURRY!!<br> Look at the image below
Crank

The output will be 10.

The while loop runs until numb is equal to or less than 13.

25 - 5 = 20

20 - 5 = 15

15 - 5 = 10, which is less than 13 so the loop stops and 10 is printed to the screen.  

4 0
3 years ago
What is the significance of XML tags?
tatyana61 [14]

Answer:

your answer would be to ur question would be B

7 0
2 years ago
Other questions:
  • Describe three general methods for passing parameters to the operating system.
    6·1 answer
  • Advances in television broadcasting have created changes in millions of U.S. families in a. ​sleep habits. b. ​conversation patt
    5·1 answer
  • Summary In this lab, you declare and initialize variables in a C++ program. The program, which is saved in a file named NewAge.c
    5·1 answer
  • Commands are organized into tabs on the
    8·2 answers
  • Can web sites contain copyright material? <br> Yes <br> No
    10·2 answers
  • What inspired john logie baird to create the television?
    11·1 answer
  • A case competitions database:You work for a firm that has decided to sponsor case competitions between teams of college business
    12·1 answer
  • 1) Using the density equation d=m/V: What is the density of a piece of metal with a mass o
    10·1 answer
  • Explain the role of a computer in education​
    9·1 answer
  • What enables image processing, speech recognition, and complex game play in Artificial Intelligence (AI)?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!