⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netserverthread.java

📁 java的团队合作代码
💻 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 + -