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]
1 year 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]1 year 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
Required
soldier1979 [14.2K]

Answer:

Declined sitting

Explanation:

You need to have a lot of abs to do that position so naturally it is not a neutral position. Hope I helped!

3 0
3 years ago
How has the growth of industries that use computer technology changed employment?
KIM [24]
Well Member The Industrial Revolution? Well If You Forgot It Was Like Making Goods Like With Your Hands But Every Since The Factories Came Works Been Kind Of Hard To Find And Such , So If The Growth Of Industries That Use Technology Changes Employment Than We Wouldn't Have Work It Would Have Been The Industrial Revolution All Over Again
8 0
3 years ago
Given a vector and a starting position, find the index of // the smallest value in the range [start, last], where last is // vec
marusya05 [52]

Answer:

The solution code is written in Python

  1. def findSmallest(vec, start):
  2.    index = start
  3.    smallest = vec[start]
  4.    for i in range(start + 1, len(vec)):
  5.        if(smallest > vec[i]):
  6.            smallest = vec[i]
  7.            index = i
  8.    return index

Explanation:

Firstly we can define a function findSmallest() that takes two input parameters, a vector, <em>vec</em>, and a starting position, <em>start </em> (Line 1).

Next, create two variables, <em>index</em> and <em>smallest</em>, to hold the current index and current value where the smallest number is found in the vector. Let's initialize them with <em>start</em> position and the value held in the<em> start </em>position (Line 3-4).

Next, create a for-loop to traverse through the next value of the vector after start position and compare it with current <em>smallest </em>number. If current <em>smallest</em> is bigger than any next value in the vector, the <em>smallest </em>variable will be updated with the new found  lower value in the vector and the index where the lower value is found will be assigned to variable<em> index</em>.

At the end return index as output.

7 0
3 years ago
The Golden State Warriors won 67 game and lost 15. How do you determine their winning percentage? What is their winning percenta
never [62]
I got 81.7% for this one
5 0
2 years ago
Read 2 more answers
PLEASE HELP!! Which of the following computing devices would best address the needs for a CYBER SECURITY ANALYST?
Tomtit [17]

Answer:high end laptop.

Explanation:

5 0
3 years ago
Other questions:
  • Web design people please help!
    7·1 answer
  • "while executing programs from the command line, most operating systems also allow the user to specify one or more ____________
    15·1 answer
  • In regard to protective actions for explosive devices, the area where the blast originates is referred to as ___________ perimet
    8·1 answer
  • The Springfork Amateur Golf Club has a tournament every weekend. The club president
    7·1 answer
  • Design a class that has an array of floating-point numbers. The constructor should accept an integer argument and dynamically al
    7·1 answer
  • Write a program that calculates the future value of an investment at a given interest rate for a specified number of years. The
    14·1 answer
  • Barat explains that if you have a cell that is the sales price of a given product, the value of which will change to produce the
    9·1 answer
  • Assume the existence of an UNSORTED ARRAY of n characters. You are to trace the CS111Sort algorithm (as described here) to reord
    14·1 answer
  • What will be the output of the following lines of code and the user's response?
    8·1 answer
  • Create a new Java program called MyInfo. Create one or more method(s) that pass the following information as parameters and prin
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!