【发布时间】:2017-05-19 01:12:06
【问题描述】:
是否可以将数组专门添加到ConcurrentLinkedQueue 中?如果是这样,.add 语句究竟会是什么样子?
这是与家庭作业相关的,但是,我的整个程序旨在对 MyObjects 执行计算(MyObjects 的默认构造函数会生成随机值来执行大量计算)。
例如:
//Note: I couldn't use the Diamond Braces for the Queue-type when posing this question
ConcurrentLinkedQueue theLinkedQueue {MyObjects[]} =
new ConcurrentLinkedQueue{MyObjects[]}();
MyObjects[] theArray = null;
for(int i = 0; i < 100; i++){
theArray = new MyObjects[CONSTANT_SIZE];
theLinkedQueue.add(theArray(objparameter1, objparameter2));
}
该程序实现了多线程,在我的线程类中,我将Queue 传递到constructor,并试图取出MyObject 数组,其中@987654329 @ temp 会指向,但到目前为止,我只能一次向我的Queue 添加一个MyObject 并拉动它。我希望能够添加相同数量的 MyObjects 作为单个组件,而不是单独添加。我已经为 NetBeans IDE 尝试了各种代码行来推荐一种抛出UnsupportedOperation Exception 的方法。如何将数组添加到我的ConcurrentLinkedQueue?
(如果我的问题很密集或令人困惑,也很抱歉,这是第一次在这里发布)。
【问题讨论】:
标签: java arrays multithreading queue