任何方向都是gr8 [英] any direction would be gr8
问题描述
我需要编写一个启动1000个线程的程序。每个线程将1添加到最初为0的变量sum。我需要通过引用传递sum到每个线程。为了通过引用传递,定义一个Integer包装器对象来保存总和。使用和不使用同步运行程序以查看效果。
Ex输出:
在线程1 sum = 0;
线程2总和= 1,
等等?
我失去了如何开始..我有一些代码我试着稍后发布
I need to write a program that launches 1000 threads. Each thread adds 1 to a variable sum that is initially 0. I need to pass sum by reference to each thread. In order to pass by reference, define an Integer wrapper object to hold the sum. Run the program with and without synchronization to see the effects.
Ex output:
At thread 1 sum = 0;
At thread 2 sum = 1,
Etc?
im lost on how to start..I have some code Ill try to post later
推荐答案
我需要编写一个启动1000个线程的程序。每个线程将1添加到最初为0的变量sum。我需要通过引用传递sum到每个线程。为了通过引用传递,定义一个Integer包装器对象来保存总和。使用和不使用同步运行程序以查看效果。
Ex输出:
在线程1 sum = 0;
线程2总和= 1,
等等?
我失去了如何开始..我有一些代码我试着稍后发布
I need to write a program that launches 1000 threads. Each thread adds 1 to a variable sum that is initially 0. I need to pass sum by reference to each thread. In order to pass by reference, define an Integer wrapper object to hold the sum. Run the program with and without synchronization to see the effects.
Ex output:
At thread 1 sum = 0;
At thread 2 sum = 1,
Etc?
im lost on how to start..I have some code Ill try to post later
直到发布代码然后我们都会保持手指交叉。
Till you post the code then we''ll all keep our fingers crossed.
我需要编写一个启动1000个线程的程序。每个线程将1添加到最初为0的变量sum。我需要通过引用传递sum到每个线程。为了通过引用传递,定义一个Integer包装器对象来保存总和。使用和不使用同步运行程序以查看效果。
Ex输出:
在线程1 sum = 0;
线程2总和= 1,
等等?
我失去了如何开始..我有一些代码我试着稍后发布
I need to write a program that launches 1000 threads. Each thread adds 1 to a variable sum that is initially 0. I need to pass sum by reference to each thread. In order to pass by reference, define an Integer wrapper object to hold the sum. Run the program with and without synchronization to see the effects.
Ex output:
At thread 1 sum = 0;
At thread 2 sum = 1,
Etc?
im lost on how to start..I have some code Ill try to post later
两个评论:
1)你不能通过Java中的引用传递任何东西;决不;真的。
2)整数是不变的;你不能将它们用于你的目的。
没有理由恐慌,你可以写自己的小班:
Two remarks:
1) You can''t pass anything by reference in Java; never; really.
2) Integers are immutable; you can''t use them for your purposes.
No reason to panic though, you can write your own little class:
有趣的是如何成为要求的一部分......?我现在在工作。我会在当天晚些时候发布代码,可能是在3:30之后...谢谢
interesting how that was part of the requirments...? I am currently at work. I will post code later in the day, probably after 3:30...Thanks
这篇关于任何方向都是gr8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!