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
Write your question here (Keep it clear and simple to get the best answer)
weeeeeb [17]
What is your favorite book?
4 0
3 years ago
Read 2 more answers
What game involves controlling a character who is trying to rescue his girlfriend from an ape?
ddd [48]

Answer:

E.  

Donkey Kong

Explanation:

5 0
3 years ago
Read 2 more answers
____ refers to the order in which values are used with operators.
mylen [45]

Answer:

b. Associativity

Explanation:

Associativity specifies the order in which operators are processed vis a vis operands/values in an expression. For example: Consider the expression: a + b + c. Here a + b is evaluated first before adding the result with c as the '+' operator is left associative. The default associativity can also be overridden by the use of parentheses. For example a + (b + c) . In this case b+c will be evaluated first.

5 0
3 years ago
Hey guys im just curious.... whats ur favorite number
Oksana_A [137]

Answer:

13

Explanation:

8 0
3 years ago
Read 2 more answers
Read the section of the article named "Duties." Which selection from the section shows a way that advertising managers get custo
TEA [102]

Answer:

They do research studies that help them to understand customers and what they want to buy.

Explanation:

4 0
3 years ago
Other questions:
  • Assume that the population of Mexico is 128 million and that the population increases 1.01 percent annually. Assume that the pop
    7·1 answer
  • How are appointments scheduled in medisoft
    12·1 answer
  • There are six different sequences for the three approval tasks: check inventory; check credit; check special terms.
    5·1 answer
  • Rebecca completed work on a computer and is verifying the functionality of the system when she finds a new problem. This problem
    14·1 answer
  • 8. A sprite is a simple spider shaped thing with n legs coming out from a center point. The angle
    10·1 answer
  • Use______ to format cells when they meet a certain criteria.
    13·1 answer
  • What is the difference between KE an PE
    8·1 answer
  • Ok who tryna play zombs royale
    7·1 answer
  • HTML question please help
    5·1 answer
  • on early ethernet networks, all computers were connected to a single wire, forcing them to take turns on a local area network (l
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!