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
Use the variables k, d, and s so that they can read three different values from standard input--an integer, a double, and a stri
Nat2105 [25]

Answer:

The c++ program to implement the given scenario is shown below.

#include <iostream>

using namespace std;

int main() {

   // variables declared as mentioned

   int k;

   double d;

   string s;

   cout << " Enter an integer value, a double value, a string value in the mentioned order " << endl;

   cin >> k >> d >> s;

   // variables printed in reverse order

   cout << " Reverse order " << endl;

   cout << s << " " << d << " " << k << endl;

   // variables printed in original order

   cout << " Original order " << endl;

   cout << k << " " << d << " " << s << endl;

   return 0;

}

OUTPUT

Enter an integer value, a double value, a string value in the mentioned order  

12 45.67 brainly

Reverse order  

brainly 45.67 12

Original order  

12 45.67 brainly

Explanation:

1. All the variables are declared as mentioned in the question.

int k;

   double d;

   string s;

2. The user is prompted to enter values for integer, double and string variables respectively. The input is accepted in the order mentioned above.

cin >> k >> d >> s;

3. The input is accepted in a single line since this is mentioned in the scenario that variables should be printed in the order in which they are read.

4. These variables are displayed to the standard output in reverse order – string, double, integer. The variables are displayed with exactly one space in between them.

cout << s << " " << d << " " << k << endl;

5. Then, variables are displayed in the original order – integer, double, string. The variables are displayed with exactly one space in between them.

cout << k << " " << d << " " << s << endl;

7 0
2 years ago
2.Use loops to create a 4X6 matrix in which the value of each element is two times its row number minus three times its column n
DiKsa [7]

Answer:

for(i=0; i<4; i++)

{

      for(j=0;j<6;j++)

      {

               A[ i ][ j ] = 2* i - 3*j;

      }

}

Explanation:

In this loop for each i = 0,1,2,3 we fill the the corresponding column values. and then move to next i value i.e. row.

3 0
3 years ago
The second letter of the Koeppen letter code gives information about:
lukranit [14]

Answer:

a. the precipitation characteristics of the climate subtype.

Explanation:

The second letter in the code represents the detailed seasonality of precipitation, it shows when during the seasons precipitation comes to that climate.

6 0
3 years ago
Advantages of desktop publishing over traditional methods include       
Licemer1 [7]
From what my teacher taught us it would be c.
6 0
2 years ago
What process does a system use to officially permit access to a file or a program CIS 502 ?
ipn [44]

Answer:

Authorization                                

Explanation:

Authorization is a security process to determine access levels related to system resources such as files, services, computer programs, data and application features. This is the method of allowing or denying access to a resource which enables the user to get access to various services and resources depending on the user's identity.

Authorization is the process that checks if a user has the permission to get access to a particular file or perform a particular action, ensuring that user has successfully authenticated himself. It refers to defining access policy.

For example a system administrator determines for the system device, in multi-user computer systems, which users are granted access to system and its resources and privileges are granted.

4 0
2 years ago
Other questions:
  • Which statement about the Paste Link option is true? A)Even if the source file (spreadsheet) is deleted, the data updates automa
    11·1 answer
  • With a _____ network connection, the computers and other devices on the network are physically connected via cabling to the netw
    13·1 answer
  • Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character o
    11·1 answer
  • Define function print_popcorn_time() with parameter bag_ounces. If bag_ounces is less than 3, print "Too small". If greater than
    14·2 answers
  • The following pseudocode is an example of ____.do stepAdo stepBif conditionC is true thendo stepDelsedo stepEendifwhile conditio
    15·1 answer
  • What is a spreadsheet program?<br> A spreadsheet program is a computerized version of _______
    5·1 answer
  • Sometimes we care about the order of a list, and need to reorder the items according to a condition (alphabetical, numerical, et
    11·2 answers
  • 4.3 Code Practice: Question 1
    12·2 answers
  • Write a function sumOfMultiples, that inputs two integers - seed and cap. The function should return the sum of all the multiple
    6·1 answer
  • What distinguishes Accenture’s Cloud capabilities from our competitors?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!