Java程序停止工作

时间:2014-12-31 05:12:30

标签: java jvm

try {
            final Connection connection =
                    DriverManager.getConnection(url,username,password);



            final AtomicInteger start = new AtomicInteger(0);
            final AtomicInteger preFix = new AtomicInteger(201401);
            final int perCount = 1000;
            ScheduledExecutorService service = Executors.newScheduledThreadPool(3);
            service.scheduleWithFixedDelay(new Runnable() {
                @Override
                public void run() {

                    String sql = "select id,class,function,remark,add_time from ";
                    sql += "table_";
                    sql += preFix.get();
                    sql += " order by id limit ";
                    sql += start.get();
                    sql += ",";
                    sql += perCount;
                    ResultSet resultSet = null;
                    List<Email> emailList = new ArrayList<Email>();
                    try{
                        PreparedStatement preparedStatement = connection.prepareStatement(sql);
                        resultSet = preparedStatement.executeQuery();
                        while (resultSet.next()){
                            Email email = new Email();
                            long  id = resultSet.getLong("id");
                            email.setId(id + "");
                            String userEmail = resultSet.getString("class");
                            email.setUserEmail(userEmail);
                            String subject = resultSet.getString("function");
                            email.setSubject(subject);
                            String content = resultSet.getString("remark");
                            email.setContent(content);
                            long addTime = resultSet.getLong("add_time");
                            email.setAddDate(addTime);
                            emailList.add(email);
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }




//                    List<Email> emailList = emailDao.getEmailList(start.get(),perCount);

                    List<Order> studentList = new ArrayList<Order>();
                    if(null != emailList && emailList.size() > 0){
                        System.out.println("emailList size:" + emailList.size());
                        for(Email email:emailList){
                            if(email.getSend() == 1){
                                Order order = new Order();
                                order.setOrderId(Integer.valueOf(email.getId()));
                                String content = new String(email.getContent());
                                order.setOrderSign(content + "verygood");
                                studentList.add(order);
                            }
                        }
                        start.set(start.get() + perCount);
                    }else{//another table

                        int n = preFix.getAndIncrement();
                        System.out.println("useing table:" + n);
                        if(n == 201412){
                            preFix.set(201401);
                        }
                        start.set(0);
                    }

                    if(null != studentList){
                        studentList.clear();
                        studentList = null;
                    }
                }
            },0,200, TimeUnit.MILLISECONDS);

        } catch (SQLException e) {
            e.printStackTrace();
        }

上面是我的程序,当使用jvm_option“-server -Xmx50m -Xms50m”时程序运行良好,但是当减少内存时这样的“-server -Xmx10m -Xms10m”,经过一秒钟的程序停止工作,而jvm是不做gc。 使用命令:jstat -gcutil 4116 2s
结果是: ![在此输入图像说明] [1]

  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT

 0.00   0.00  12.72  34.90  55.08     36    0.117    36    0.666    0.783

 0.00   0.00  12.72  34.90  55.08     36    0.117    36    0.666    0.783

 0.00   0.00  12.72  34.90  55.08     36    0.117    36    0.666    0.783

我想知道为什么

1 个答案:

答案 0 :(得分:1)

10mb是一个非常少量的内存,在我再进一步之前,我想说明内存不足。永久空间占该数额的55.08%。老一代占34.90%,伊甸园占12.72%。这相当于允许的最大堆大小的102.7%,并且我猜测在读取后不久就抛出了OutOfMemoryError。

https://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jstat.html#gcutil_option