?? netserverthread.java
字號:
package com.briup.impl.net;import java.io.InputStream;import java.io.ObjectInputStream;import java.net.Socket;import java.util.Collection;import java.util.Date;import com.briup.Backup;import com.briup.Config;import com.briup.DBStore;import com.briup.Log;import com.briup.exception.BackupException;import com.briup.exception.DBStoreException;public class NetServerThread extends Thread { private Socket s; private Config config; public NetServerThread(Socket s,Config config){ this.config = config; this.s = s; start(); } @Override public void run() { ObjectInputStream ois =null; InputStream is =null; Collection c =null; Collection backdatas; DBStore ds = null; Backup bu = null; Log log =null; try { ds = config.getDBStore(); bu =config.getBackup(); log = config.getLog(); is=s.getInputStream(); ois=new ObjectInputStream(is); c = (Collection) ois.readObject(); log.writeInfo(new Date(System.currentTimeMillis()) +"Gather server receive :" + c.size() + "records!!"); backdatas = bu.load();//獲取備份的數據 bu.clear(); if(backdatas!= null){ log.writeInfo(new Date(System.currentTimeMillis()) + "there are " + backdatas.size() + " recorde to load!!"); c.addAll(backdatas);//連同備份數據一起加入到集合c中 } } catch (Exception e) { e.printStackTrace(); log.writeError(e.getMessage()); }finally{ try{ if(ois!=null){ ois.close(); } if(s!= null){ s.close(); } }catch(Exception e){ e.printStackTrace(); log.writeError(e.getMessage()); } } try { ds.insert(c); log.writeInfo(new Date(System.currentTimeMillis())+"there are " + c.size() + "insert into the db"); } catch (DBStoreException e) { e.printStackTrace(); try { bu.store(c); log.writeInfo(new Date(System.currentTimeMillis()) +"there are " + c.size() + " recorde to store!"); } catch (BackupException e1) { // TODO Auto-generated catch block e1.printStackTrace(); log.writeError(e1.getMessage()); } } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -