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
Element primer a partir del qual es generarà l'energia central solar fotovoltaica
Juliette [100K]
No speak a Spanish ............
7 0
3 years ago
A college student needs a laptop that can be used while committing on the train and sitting in a lecture
Westkost [7]
You could get a laptop for like 200 that could run well and enough space for stuff.
4 0
3 years ago
Is jesus dead or alive
Morgarella [4.7K]

Answer:

Explanation:

i think he alive but in heaven i dunno

8 0
3 years ago
By converting a given collection of tables to an equivalent third normal form collection of tables, you remove any problems aris
dolphi86 [110]

Answer:

The answer is "functional".

Explanation:

It's a relation of two attributes, usually between the primary key and other main attributes of a table. It turns the collection of tables into a third standard table array.

  • It allows you to controls the quality of data into the database.  
  • It is the disparity between the positive and weak architecture of the database plays a crucial role.

4 0
2 years ago
In the main function, define five variables of type int, named: first, second, third, fourth, and total. Also in the main functi
fiasKO [112]

Answer:

  1. import java.util.Scanner;
  2. public class num8 {
  3.    public static void main(String[] args) {
  4.    int first, second, third, fourth,total;
  5.    double decimalOne, decimalTwo, decimalTotal;
  6.    }
  7.    public static void getData(int first, int second, int third, int fourth, double decimalOne, double decimalTwo){
  8.        System.out.println("Enter the Values");
  9.        Scanner in = new Scanner(System.in);
  10.        first=in.nextInt();
  11.        second=in.nextInt();
  12.        third=in.nextInt();
  13.        fourth=in.nextInt();
  14.        decimalOne = in.nextDouble();
  15.        decimalTwo = in.nextDouble();
  16.    }
  17.    public static int computeTotal(int first, int second, int third){
  18.        return first+second+third;
  19.    }
  20.    public static int computeTotal(int first, int second, int third, int fourth){
  21.        return first+second+third+fourth;
  22.    }
  23.   public static double computeTotal(double decimalOne, double decimalTwo){
  24.        return decimalOne+decimalTwo;
  25.    }
  26.    public static void printAll( int first, int second, int third){
  27.        System.out.println("Number one, two and three are: "+first+" "+second+" "+third);
  28.    }
  29.    public static void printAll( int first, int second, int third, int fourth){
  30.        System.out.println("Number one, two and three and four are: "+first+" "+second+
  31.                " "+third+" "+fourth);
  32.    }
  33.   public static void printAll( int first, int second, int third, int fourth, int fifth){
  34.        System.out.println("Number one, two and three and four are: "+first+" "+second+
  35.                " "+third+" "+fourth+" "+fifth);
  36.    }
  37.    public static void printAll( double first, double second, double third){
  38.        System.out.println("Number one, two and three and four are: "+first+" "+second+
  39.                " "+third);
  40.    }
  41. }

Explanation:

This solution is provided in Java:

All the variable declarations are done in the main method (lines 3-6)

Eight methods as specified in the question are created (Lines 7, 17, 20, 23, 26, 29, 33 and 37).

Observe the concept of Method Overloading (i.e. methods with same name and return types but different parameter list)

8 0
3 years ago
Other questions:
  • Ben buys an Olympus E-PL2 from Sony which starts malfunctioning. When he opts for an exchange, the customer representative says
    11·1 answer
  • "The fact that we could create and manipulate an Account object without knowing its implementation details is called"
    9·1 answer
  • To ease giving access to network resources for employees, you decide there must be an easier way than granting users individual
    9·1 answer
  • Page UND
    8·1 answer
  • Many computer programs contain ____ that detail the specific instructions a computer should perform (in a specific order) to car
    9·1 answer
  • Anyone know the answer I need help
    12·1 answer
  • 4. Written record of all transactions in your checking account
    5·2 answers
  • Please choose the correct answer please tell fast​
    15·1 answer
  • Each instruction that the CPU receives contains two parts -
    12·1 answer
  • Your project will require a 7-day work week rather than the traditional 5-day. How can you adapt the software to this new schedu
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!