【发布时间】:2013-09-03 22:11:04
【问题描述】:
有什么方法可以从loop 返回一个值并从我离开的地方继续?
在下面的sn-p中,我想返回currVm的当前值。但我做不到。
在sn-p的最内层循环中:
while(c <= currVm) {
allocatedVm(currVm);
c++;
}
一个名为allocatedVm 的函数被调用。我想返回currVm 的值并从我离开的地方重新开始。有什么办法吗?
@Override
public int getNextAvailableVm() {
Set<String> dataCenters = confMap.keySet();
for (String dataCenter : dataCenters) {
LinkedList<DepConfAttr> list = confMap.get(dataCenter);
Collections.sort(list, new MemoryComparator());
int size = list.size() - 1;
int count = 0;
while(size >= 0) {
DepConfAttr dca = (DepConfAttr)list.get(count);
int currVm = dca.getVmCount();
int c = 0;
while(c <= currVm) {
allocatedVm(currVm); // RETURN currVm
c++;
}
count++;
size--;
}
}
}
【问题讨论】:
-
很难猜出您在说什么,因为您没有向我们展示allocatedVm 方法。你从哪里返回这个值,你想恢复哪一部分?
-
@RohitJain 为什么要
allocatedVm方法? -
@RohitJain,OP 期待 LazySeq(Java 8)、Stream(scala) 之类的东西
-
@RohitJain 我想在调用
allocatedVM后立即返回值