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
How do you change the top and bottom margins of an entire document?
Firdavs [7]

Answer:

Click the Page Layout tab and then the Margins button.

Choice D is correct

Explanation:

In order to change the top and bottom margins of an entire document, simply

Click the Page Layout tab and then the Margins button.

I hope this helps..

Great Day ahead

4 0
3 years ago
Read 2 more answers
Alguien porfavor me dice como cambiar de idioma en brainly
Kitty [74]

Answer:

Creo que necesitas crear una nueva cuenta en el Brainly español. Para encontrarlo, tal vez pueda buscar una pregunta aleatoria en Internet seguida de Brainly y, con suerte, encontrará la correcta. Luego crea una cuenta en ese Brainly. Al menos pienso cómo lo haces.

5 0
2 years ago
Do you watch markiplier?
ki77a [65]

Answer: Yes

Explanation: He is cool

5 0
3 years ago
Read 2 more answers
Is iPhone better than android
andriy [413]

Answer:

It's up to personal preference.

Explanation:

iPhone/Apple gives more compliments to security than Android.

Android has more friendly user GUI and dev tools.

4 0
3 years ago
Read 2 more answers
A well-diversified portfolio needs about 20-25 stocks from different categories is this True or False?
borishaifa [10]

Usually they hold 15-20 as the minimum of the portfolios

So I would say True

3 0
3 years ago
Read 2 more answers
Other questions:
  • Should I learn Python, C++, C# or VB to start off programming games for Windows. Open to other language recommendations as well!
    6·1 answer
  • How do u determine the voltage across diode
    15·1 answer
  • How should you dress for a phone interview
    12·2 answers
  • The file extensions .webm, .m4v, and .ogv are used for:
    15·1 answer
  • What is the name for a partition that has been formatted and assigned a drive letter?
    8·1 answer
  • What is the subnet mask ?
    9·2 answers
  • What does the -pwd switch do? how can you make dsadd bring up a prompt asking for the users password?
    10·1 answer
  • Which operating system (OS) is used to run your laptop?
    15·2 answers
  • When an external device becomes ready to be serviced by the processor the device sends a(n)_________ signal to the processor.
    8·1 answer
  • (C) Describe about the different types of computer<br> peripherals and memory devices.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!