将arraylist的值分配给Thread Array [英] assign values of arraylist to Thread Array

查看:74
本文介绍了将arraylist的值分配给Thread Array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含10个值的arraylist.

我还创建了一个线程数组.
我想将线程arraylist值平均分配给数组中的每个线程,线程数为5.
IE.每个线程将从数组列表中获取2个值.

如何将arraylist中的这两个值分配给每个线程?
另外,我还需要并行运行这些线程.

I have an arraylist which contains 10 values.

I have also created a thread array.
I want to assign the thread arraylist values equally to each thread in the array, having a thread count as 5.
ie. Each thread will get 2 values from array list.

How do I assign those two values from arraylist to each thread?
Also I need to run those threads in parallel.

推荐答案

您可以将arraylist设为静态的全局公共项,并让每个线程访问它自己的索引在那个数组中.

编辑================

再一次,我不明白为什么将它评为1.这是一次诚实的尝试,目的是使您指出正确的方向.当我没有时间/渴望编写和测试它时,我将不提供代码.
You could make the arraylist a static globally public item, and just let each thread access it''s own index in that array.

EDIT ================

Once again, I don''t understand why this was voted a 1. It was an honest attempt at getting you pointed in the right direction. I''m not going to provide code when I don''t have time/desire to write and test it.


这篇关于将arraylist的值分配给Thread Array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆