【发布时间】:2020-05-26 03:04:07
【问题描述】:
我正在调用一个函数来从另一个函数创建优先级队列。
void readparameters() throws NumberFormatException, IOException
{
try (BufferedReader br = new BufferedReader(new FileReader("FB2010-1Hr-150-0.txt"))) {
while (br.ready()) {
Coflow_All.add(br.readLine());
}
}
Framework.size = Coflow_All.size();
System.out.println("\nThere are "+Framework.size+" coflows entries\n");
for(queue_entry=1;queue_entry<=15;queue_entry++)
{
//Extract a Coflow and satisfy conditions
ArrayList<Integer> Coflow_each = new ArrayList<Integer>();
String input = Coflow_All.get(coflow_pick);
int find=input.indexOf(":");
if (find != -1)
{
//this will give substring
input= input.substring(0 , find);
}
String[] numbers = input.split(" ");
for (String s : numbers)
{
Coflow_each.add(Integer.parseInt(s));
}
//System.out.println(Coflow_each);
createqueue(Coflow_each.get(0),Coflow_each.get(1),Coflow_each.get(2),Coflow_each.get(4));
coflow_pick++;
}
void createqueue(int id,int Arrivaltime,int mappers_req,int reducers_req) throws NumberFormatException
{
Framework.list.clear();
Collections.addAll(Framework.list, Arrivaltime,mappers_req,reducers_req);
//System.out.println("The list is "+Framework.list);
//Analyze the parameters in Framework.list and then do the entry in queue
for(int i=1;i<=mappers_req;i++)
{
Queue1.add(new Create_queue(id,Framework.list));
System.out.println(Queue1.size());
queue_entry++;
}
java.util.Iterator<Create_queue> it = Queue1.iterator();
while(it.hasNext()) {
System.out.println(Queue1.poll().toString());
}
System.out.println(Queue1.size());
}
}
但是,一旦我在循环之外,显示的队列大小就为 0。我希望队列的大小只增加而不是 0。请帮忙!!
所有变量都在类中定义,所以不用担心那部分。
【问题讨论】:
-
是的,但是如果不显示队列是如何生成和处理的,您将不会得到答案。
-
在minimal reproducible example 上发布您的问题将是您快速获得严肃和体面答案的最佳选择。请完整阅读链接。
-
当前代码的格式很差,也无法编译。是的,minimal reproducible example 可以简化问题,代码将再次成为您的最佳选择。
-
顺便说一句,我强烈建议您开始遵循正常的 Java 命名约定。目前,您的方法和变量的命名方式不一致并且不遵循 Java 约定。
-
您应该添加更多详细信息,您使用的所有类。并且请使用类和对象的驼峰命名约定!
Create_queue类应该是CreateQueue,Coflow_each变量应该是coflowEach...
标签: java