Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Eclipse中的线程自动停止(冻结)_Java_Eclipse_Multithreading - Fatal编程技术网

Java Eclipse中的线程自动停止(冻结)

Java Eclipse中的线程自动停止(冻结),java,eclipse,multithreading,Java,Eclipse,Multithreading,我正在eclipse中运行一个线程来从mysql服务器获取数据。这根线很好用。问题是在一段时间后线程停止运行(在6到8小时内)。线程被冻结。之后,我必须手动关闭并重新运行程序。Eclipse在windows server 2012 r2计算机上运行。未显示任何错误或异常 主课 public class Main { private final static int fONE_DAY = 1; private final static int fZERO_MINUTES

我正在eclipse中运行一个线程来从mysql服务器获取数据。这根线很好用。问题是在一段时间后线程停止运行(在6到8小时内)。线程被冻结。之后,我必须手动关闭并重新运行程序。Eclipse在windows server 2012 r2计算机上运行。未显示任何错误或异常

主课

public class Main {

      private final static int fONE_DAY = 1;
      private final static int fZERO_MINUTES = 0;

      public static void main(String[] argv) {

        Timer timer1 = new Timer();
        Timer timer4 = new Timer();


        try {
        timer1.scheduleAtFixedRate(new CearteSDQuatation(),500 , 1000*60*4);// 4min
        System.out.println("timer 1 : createSDQuotation");
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
        timer4.schedule(new GarbageCol(), 5000, 1000 * 60 * 60);// 60mins
        System.out.println("timer 2 : garbageCollector");
        } catch (Exception e) {
            e.printStackTrace();
        }



}

      private static Date getTomorrowRunningTime(int Ftime){
            Calendar tomorrow = new GregorianCalendar();
            tomorrow.add(Calendar.DATE, fONE_DAY);
            Calendar result = new GregorianCalendar(
              tomorrow.get(Calendar.YEAR),
              tomorrow.get(Calendar.MONTH),
              tomorrow.get(Calendar.DATE),
              Ftime,
              fZERO_MINUTES 
            );
            return result.getTime();
          }




    }
CEARTESDquation类

public class CearteSDQuatation extends TimerTask {

    DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");;

    DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    Date date = new Date();

    DBPool_SF pooler;   
    DataSource dataSource;
    DataSource dataSource1;
    DBTableQueryExcecutre qex = null;
    DBTableQueryExcecutre qex3 = null;
    DBTableQueryExcecutre qex1 = null;
    DBTableQueryExcecutre qex2 = null;

    ArrayList<String> dates = null;
    HashSet<String> dateSet = null;
    Iterator<String> itr = null;
    StringBuilder inClause;

    int rcount = 0;



    StringBuilder sbDel = null;
    int delStatus = 0;
    ArrayList<String> elements = new ArrayList<String>();// for update query
    int queryStatus = 0;
    String delete_query1 = " ";
    String strDate = "";
    String strMatnr = "";
    String strkunnr = "";


      // Object for table data
      private Object[][] itemData;


    RFCHandler handler;


      public CearteSDQuatation(){
        handler = new RFCHandler();
        }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        try{
        CallItem_ListCreate();
        CallRFC_CreateSDQuata();
        System.out.println("Thread Run");
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }


    private void CallItem_ListCreate() {
        // TODO Auto-generated method stub
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        System.out.println(dateFormat.format(date));

        System.out.println("Create Quotation : Started sub excecutions List create...");
        String sbQuery3 = "SELECT d.plant, h.dis_channel, h.order_no, h.Rep_no," +
                "h.dealer_no,h.order_date,h.last_date, d.items_no," +
                "d.quantity " +
                "FROM tbl_item_list as d, " +
                "tbl_items_header_t as h " +
                "where d.order_no = h.order_no " +
                "and h.status <> 'X'" ;
        try {
        pooler = DBPool_SF.getInstance();
        dataSource1 = pooler.getDataSource();
        System.out.println("pooler");
        } catch (Exception e1)
        {
            e1.printStackTrace();
        }

        try {


        Connection con3 = dataSource1.getConnection();
        con3.setAutoCommit(false);

        Statement st = con3.createStatement();      
        ResultSet rs = st.executeQuery(sbQuery3);





        int lineitem = 0;

        try {
            rs.last();
            rcount = rs.getRow();
            rs.beforeFirst();
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
        System.out.println("while loop");
        itemData = new Object[9][rcount];

        while(rs.next())
        {           
            itemData[0][lineitem] = rs.getString("plant");
                    lineitem = lineitem + 1;
        }
        } catch (SQLException e)
        {
            e.printStackTrace();
        }



    }

    public void CallRFC_CreateSDQuata()
    {
        System.out.println("Create Quotation : Started sub excecutions");       
        JCO.Table IT_LIST = null;
        JCO.Table IT_LIST1 = null;
        JCO.Table IT_REF = null;
        JCO.Table IT_Msg = null;
        try {

            if(rcount > 0)
            {

            handler.createRFCFunction("ZSL");
            IT_LIST = handler.getTablePara("IT_LIST");  
            IT_LIST1 = handler.getTablePara("IT_LIST1");    

            for(int x = 0; x < rcount; x++ )
            {
                IT_LIST.appendRow();
                IT_LIST1.appendRow();

                IT_LIST.setValue( itemData[0][x].toString().trim(), "SAL_ORG");                     

            }

            handler.excFunction();
            IT_REF = handler.getTablePara("IT_REF");    
            IT_Msg = handler.getTablePara("IT_MSG");
            handler.releaseClient();

            int int_row = IT_REF.getNumRows();

            if (int_row > 0) {
                this.tableOparator(IT_REF , IT_Msg);

            }   
            }

        } catch (Exception ex) {
            handler.releaseClient();
            ex.printStackTrace();
        }

        finally {
            // Release the client to the pool
            //handler.releaseClient();
            rcount = 0;
        }
    }


    public String leadingZeros(String s, int length) {
         if (s.length() >= length) return s;
         else return String.format("%0" + (length-s.length()) + "d%s", 0, s);
    }

    public void tableOparator(JCO.Table table , JCO.Table table1 ) throws Exception {

        pooler = DBPool_SF.getInstance();
        dataSource = pooler.getDataSource();
        Connection con = dataSource.getConnection();
        con.setAutoCommit(false);

        qex = new DBTableQueryExcecutre(con);


        StringBuilder sbQuery = new StringBuilder(
                "INSERT INTO tbl_RefQut (QuatationNo,RefOrderNumber) VALUES");
        System.out.println("COL -->"+table.getNumRows()
                + " records to insert for tbl_RefQut");

        // --- create query ---------------------------------
        for (int i = 0; i < table.getNumRows(); i++) {
            // table.setRow(i);
            sbQuery.append("(?,?),");

        }


        sbQuery.deleteCharAt(sbQuery.length() - 1);
        sbQuery.append(";");
        qex.setUpdateQuery(sbQuery.toString());// *****************
        elements.clear();
        for (int i = 0; i < table.getNumRows(); i++) {
            table.setRow(i);

            elements.add(table.getString("SDOCUMENT").trim());
            elements.add(table.getString("ONUMBER").trim());

        }

            qex.updateInsertQuery(elements);            
            con.commit();




            StringBuilder sbQuery1 = new StringBuilder(
                    "INSERT INTO tbl_item_order_msg (order_no,msg) VALUES");
            System.out.println("COL -->"+table1.getNumRows()
                    + " records to insert for  tbl_item_order_msg");

            // --- create query ---------------------------------
            for (int i = 0; i < table1.getNumRows(); i++) {
                // table.setRow(i);
                sbQuery1.append("(?,?),");

            }


            sbQuery1.deleteCharAt(sbQuery1.length() - 1);
            sbQuery1.append(";");
            qex.setUpdateQuery(sbQuery1.toString());// *****************
            elements.clear();
            for (int i = 0; i < table1.getNumRows(); i++) {
                table1.setRow(i);

                elements.add(table1.getString("ORDER_NUMBER").trim());
                elements.add(table1.getString("MESSAGE").trim());

            }

                qex.updateInsertQuery(elements);            
                con.commit();




            for (int i = 0; i < table.getNumRows(); i++) {
                table.setRow(i);
            String sbQuery2 = "update tbl_items_header_t set status = 'X' where order_no  = '" + table.getString("ORDER_NUMBER").trim() + "';"; 
            int rcount = qex.runQuery(sbQuery2);            
            System.out.println("tbl_items_header_t Rows -->"+rcount + "Status Updated");
            con.commit();
            }


            qex.closeConnections();         

        System.out.println("COL --> Cycle Finished....");
    }


}
公共类ceartesquation扩展了TimerTask{
DateFormat格式化程序=新的SimpleDataFormat(“dd.MM.yyyy”);;
DateFormat DateFormat=新的SimpleDateFormat(“dd.MM.yyyy”);
日期=新日期();
DBPool_SF pooler;
数据源数据源;
数据源数据源1;
DBTableQueryExcecutre qex=null;
DBTableQueryExcecutre qex3=null;
DBTableQueryExcecutre qex1=null;
DBTableQueryExcecutre qex2=null;
ArrayList日期=空;
HashSet-dateSet=null;
迭代器itr=null;
恶劣天气;
int rcount=0;
StringBuilder sbDel=null;
int delStatus=0;
ArrayList elements=new ArrayList();//用于更新查询
int queryStatus=0;
字符串delete_query1=“”;
字符串strDate=“”;
字符串stratmnr=“”;
字符串strkunnr=“”;
//表数据的对象
私有对象[][]itemData;
钱德勒·汉德勒;
公营部门{
handler=new RFCHandler();
}
@凌驾
公开募捐{
//TODO自动生成的方法存根
试一试{
CallItem_ListCreate();
CallRFC_CreateSDQuata();
System.out.println(“线程运行”);
}
捕获(例外e){
e、 printStackTrace();
}
}
私有void CallItem_ListCreate(){
//TODO自动生成的方法存根
DateFormat DateFormat=新的简化格式(“yyyy/MM/dd HH:MM:ss”);
日期=新日期();
System.out.println(dateFormat.format(date));
System.out.println(“创建报价单:开始子执行列表创建…”);
String sbQuery3=“选择d.plant、h.dis\u channel、h.order\u no、h.Rep\u no,”+
h.经销商编号,h.订单日期,h.最后日期,d.项目编号+
“d.数量”+
从tbl_项目列表中选择d+
“tbl\U项目\U标题\U t为h”+
“其中d.订单号=h.订单号”+
“和h.状态‘X’”;
试一试{
pooler=DBPool_SF.getInstance();
dataSource1=pooler.getDataSource();
System.out.println(“pooler”);
}捕获(异常e1)
{
e1.printStackTrace();
}
试一试{
Connection con3=dataSource1.getConnection();
con3.设置自动提交(错误);
语句st=con3.createStatement();
结果集rs=st.executeQuery(sbQuery3);
int lineitem=0;
试一试{
rs.last();
rcount=rs.getRow();
rs.beforeFirst();
}
捕获(例外情况除外){
例如printStackTrace();
}
System.out.println(“while循环”);
itemData=新对象[9][r计数];
while(rs.next())
{           
itemData[0][lineitem]=rs.getString(“工厂”);
lineitem=lineitem+1;
}
}捕获(SQLE异常)
{
e、 printStackTrace();
}
}
public void CallRFC_CreateSDQuata()
{
System.out.println(“创建报价单:开始子执行”);
JCO.Table IT_LIST=null;
JCO.Table IT_LIST1=null;
JCO.Table IT_REF=null;
JCO.Table IT_Msg=null;
试一试{
如果(rcount>0)
{
createRFCFunction(“ZSL”);
IT_LIST=handler.getTablePara(“IT_LIST”);
IT_LIST1=handler.getTablePara(“IT_LIST1”);
对于(int x=0;x0){
这个表处理器(IT_REF,IT_Msg);
}   
}
}捕获(例外情况除外){
handler.releaseClient();
例如printStackTrace();
}
最后{
//将客户端释放到池中
//handler.releaseClient();
rcount=0;
}
}
公共字符串前导零(字符串s,整数长度){
如果(s.length()>=length)返回s;
else返回String.format(“%0”+(length-s.length())+“d%s”,0,s);
}
公共void tableOperator(JCO.Table,JCO.Table table1)引发异常{
pooler=DBPool_SF.getInstance();
dataSource=pooler.getDataSource();
Connection con=dataSource.getConnection();
con.setAutoCommit(假);
qex=新的dbtablequeryexecutre(con);
StringBuilder sbQuery=新建StringBuilder(
“插入tbl_RefQut(数量编号、重新排序编号)值”);
System.out.println(“COL-->”+table.getNumRows()
+“为tbl_RefQut插入的记录”);
//---创建查询---------------------------------
对于(int i=0;i