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.   


    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.   

    1.不知道快速是要多快,直接遍历算快吗?(通过Entry对象)
    2.永久区是指java虚拟机中的那个方法区吗?如果是那么你一直往运行时常量池里面放数据就好了。并且不要让他回收。List<String> list = new ArrayList<String>();
    int i = 0;
    while(true){
        list.add(String.valueOf(i++).intern());
    }3.不知道
    4.再看看
      

  3.   

    System.out.println(map.toString());
    这样算快吗。。
      

  4.   

    ...
    这有意义吗?利用Map.Entry 来迭代也不知道满足不满足笔试题的答案..
      

  5.   

    看看源码
            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;
            }}
      

  6.   

    第四題貌似也沒啥問題,難道是加多了list溢出算問題?
      

  7.   

    if(list.size() <= 0)  需要改为  while(list.size() <= 0)这里必用while 不能用if 否则产生所谓的虚假唤醒。 
      

  8.   

    www.devguli.com/blog/eng/spurious-wakeup
    JLS third允許了虛假喚醒,可能是爲了提升多核硬件的性能