1 请编写代码实现快速输出map里的键值对.2 请写代码造成永久区溢出3 请列举java中常见的几种远程调用方式,并说明应用场景4 下面的代码大部分情况下没有问题,在什么情况下会有问题?为什么?public class Stack { LinkedList list = new LinkedList(); public synchronized void push(Object x){ synchronized(this){ list.addLast(x); notify(); } } public synchronized Object pop() throws Exception{ synchronized(this){ if(list.size() <= 0){ wait(); } return list.removeLast(); } } public static void main(String[] args) {
}}
还有一个设计题,感觉非常不好处理~.改天发帖单独求教!
}}
还有一个设计题,感觉非常不好处理~.改天发帖单独求教!
1.
for(Map.Entry<String, String> entry : map.entrySet()){
System.out.println(entry.getKey()+","+entry.getValue());
}
2.
//-XX:PermSize=10M -XX:MaxPermSize=10M
public static void main(String[] args) {
// 使用List保持着常量池引用,压制Full GC回收常量池行为
List<String> list = new ArrayList<String>();
// 10M的PermSize在integer范围内足够产生OOM了
int i = 0;
while (true) {
list.add(String.valueOf(i++).intern());
}
}
3.RMI,EJB4.if(list.size() <= 0)需要改为while(list.size() <= 0)
2.永久区是指java虚拟机中的那个方法区吗?如果是那么你一直往运行时常量池里面放数据就好了。并且不要让他回收。List<String> list = new ArrayList<String>();
int i = 0;
while(true){
list.add(String.valueOf(i++).intern());
}3.不知道
4.再看看
这样算快吗。。
这有意义吗?利用Map.Entry 来迭代也不知道满足不满足笔试题的答案..
public final String toString() {
return getKey() + "=" + getValue();
}
调的是内部Entry接口里的方法
static class Entry<K,V> implements Map.Entry<K,V>
public final K getKey() {
return key;
} public final V getValue() {
return value;
}}
JLS third允許了虛假喚醒,可能是爲了提升多核硬件的性能