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
Matt goes to an Internet café and tries to access his emails. The email client asks Matt to enter his email address along with t
Radda [10]

Answer:

acknowledging

Explanation:

it has to be d

6 0
3 years ago
How to scan documents from printer to computer?
Romashka-Z-Leto [24]
The printer should have a control panel. Then you gotta touch Computer to scan to the computer that is connected. Then, touch the name of the computer that you would like to save the scan to. Lastly, touch<span> the scan-to type that corresponds to the document or photo you are scanning.

(By the way, anytime I said 'touch' it meant touch on control panel I believe)

Hope O helped and I apologize if it did not because I own a Mac with no printer. :)</span>
3 0
3 years ago
Write a program using python 3 that asks the user how many integers they would like to enter. You can assume that this initial i
mixer [17]

I've included my code in the picture below. Best of luck.

8 0
2 years ago
Hard disk is a sequential data access medium. true or false?​
Crazy boy [7]

My answer is TRUE

Explanation:

Hope it help!!

3 0
2 years ago
What feature, once activated, can't be disabled without reinstalling all domain controllers within a forest?
larisa86 [58]

The feature in which when once has activated can’t be disabled without having it to be reinstalled in all of the domain controllers inside the forest is the Active Directory Recycle Bin. The Active Directory Recycle Bin is responsible for having to minimize the service directory by having to enhance the ability of preserving and to restore deleted objects without being able to restore it with the use of the active directory data.

8 0
2 years ago
Other questions:
  • True or False?
    8·1 answer
  • What is the best computer for college?
    12·1 answer
  • The presentation layer describes the layer where computers interact with _____
    8·2 answers
  • A utility program that makes a copy of all files or selected files that are in the libraries is called ______
    6·1 answer
  • Which of the following is a hardware component used to hold the BitLocker encryption key and ensures encrypted data is not acces
    5·1 answer
  • Think of an example in your life where a number could be described as data, information, and knowledge
    14·1 answer
  • Kristi, an event planner, wants to store caterers’ names and contact information in an organized manner. Kristi will MOST LIKELY
    13·1 answer
  • Array Challenge Have the function ArrayChallenge (arr) take the array of numbers stored in arr and return the string true if any
    9·1 answer
  • Write the difference between left-sentential form and <br> right-sentential form
    13·1 answer
  • The…..executed simple
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!