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
Consider an Erlang loss system. The average processing time is 3 minutes. The average inter-arrival time is 3 minutes. The numbe
AnnyKZ [126]

Answer:

r = 1

Explanation:

Average processing time ( p ) = 3 minutes

Average inter-arrival time ( a ) = 3 minutes

number of servers ( m ) = 3

<u>Determine the value of r </u>

r ( offered load ) = p/a

                          = 3 / 3  = 1

∴ value of r ( offered load ) = 1

3 0
3 years ago
Describe two types of images you can open in photoshop
vredina [299]

Answer: PSD JPEG PNG

Explanation:

6 0
3 years ago
Create a conditional expression that evaluates to string "negative" if userVal is less than 0, and "non-negative" otherwise. Ex:
Goryan [66]

Answer:

PROGRAMMING APPROACH:

  • Define the necessary header file using namespace.
  • Define the main() method.
  • Declare variable inside the function().
  • Print result.

Explanation:

Required C++ Code:

#include<iostream>

#include<string>

using namespace std;

int main()

{

  string condStr;

  int userVal;

  cin>>userVal;

  condStr=(userVal<0)?("negative"):("non-negative");

  cout<<userVal<< " is "<< condStr <<"."<<endl;

}

OUTPUT:

-2

-2 is negative.

5 0
3 years ago
To re-use saved export steps, tap or click the saved exports button on the ____ tab on the ribbon.
defon
The correct answer that would best complete the given statement above would be the words EXTERNAL DATA. Here is the complete statement. <span>To re-use saved export steps, tap or click the saved exports button on the EXTERNAL DATA tab on the ribbon. Hope this answers your question. </span>
3 0
3 years ago
The first thing you must consider in any type of communication is ______.
Wittaler [7]
As for this problem together with the options as answers presented with it, the most probable and the most likely answer would be C. the purpose of the communication.

The first thing you must consider in any type of communication is the purpose of the communication itself. Determining the purpose behind the communication would, in turn, pave way to determining the other things that is needed to be determined such as the type of communication, the style of communication, the timing of the communication, and so on and so forth.
5 0
3 years ago
Read 2 more answers
Other questions:
  • Quick question how the internet has impacted y’all life ? 5 sentences or more
    8·2 answers
  • PLEASE HELPP!! WILL MARK BRAINLIEST!!~~~~~
    11·1 answer
  • A5.3 1012 kg satellite is 1,800 m from another satellite that has a mass of 3.5 x 108 kg. What is the gravitational
    6·1 answer
  • An ink-jet printer is a type of impact printer. <br> a. True <br> b. False
    8·1 answer
  • Write a statement that increments numUsers if updateDirection is 1, otherwise decrements numUsers. Ex: if numUsers is 8 and upda
    11·1 answer
  • Next, go to the mw_tour.html file. Within the document head, create links to the mw_layout.css and mw_styles.css style sheet fil
    10·1 answer
  • Betty set up an account on a popular social networking website. she wants to know whether the privacy policy is effective for he
    14·1 answer
  • Select the best answer to the following question.
    5·1 answer
  • A health care provider approaches Accenture to help them increase their efficiency through an advanced data science platform.Wha
    8·1 answer
  • What is the purpose of memory address?​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!