- import java.util.ArrayList;
- import java.util.List;
- public class NumberManager {
-
- private int lastNumber=1;
- private List<Integer> queueNumber=new ArrayList<Integer>();
- public synchronized int generateNewManager() //这个synchronized是干啥的?加在这儿起什么作用啊?
- {
- queueNumber.add(lastNumber);
- return lastNumber++;
- }
- public synchronized int fetchServiceNumber()
- {
- return queueNumber.remove(0);
- }
- }
复制代码 |