📄 collectthread.java
字号:
package com.msd;
import java.sql.*;
import java.util.*;
public class CollectThread implements Runnable {
private String idKey = null;
private Connection conn = null;
private long bTime = 0L;
public CollectThread(String key) {
this.idKey = key;
bTime = (Calendar.getInstance()).getTimeInMillis();
getConn();
}
public void run() {
try {
while(true) {
checkConn();
Vector v = getFileList();
if(v == null) {
try {
Thread.sleep(5000);
} catch(Exception e) { }
continue;
} else {
for(int i = 0 ;i < v.size() ;i ++) {
(FileList.getInstance()).addFile((SendFile)v.get(i));
}
v = null;
try {
Thread.sleep(2000);
} catch(Exception e) { }
}
}
} catch(Exception ex) {
Log.logger.error("CollectThread run Error: " + ex.toString());
(CollectThreadFactory.getInstance()).ExceptionOut(idKey);
}
}
private void getConn() {
try {
conn = DriverManager.getConnection("jdbc:oracle:thin:@221.5.236.34:1521:msdwap", "OEM_MSDWAP", "msdwap01");
conn.setAutoCommit(false);
} catch(Exception e) {
Log.logger.error("CollectThread Connection create Error: " + e.toString());
}
}
private void checkConn() {
long tmp = (Calendar.getInstance()).getTimeInMillis();
if((tmp - bTime) >= 86400000) {
try {
conn.close();
conn = null;
} catch(Exception e) { }
reCreate();
} else {
return;
}
}
private void reCreate() {
getConn();
bTime = (Calendar.getInstance()).getTimeInMillis();
}
private Vector getFileList() {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement("select * from F_SendFileTable");
ResultSet rs = ps.executeQuery();
Vector v = null;
while(rs.next()) {
if(v == null)
v = new Vector();
SendFile sf = new SendFile(rs.getString("filename"),rs.getInt("flag"));
v.add(sf);
}
rs.close();
rs = null;
ps.close();
ps = null;
if(v != null) {
ps = conn.prepareStatement("delete from F_SendFileTable where filename = ?");
for(int i = 0;i < v.size(); i++) {
SendFile sf = (SendFile)v.get(i);
ps.setString(1,(sf.fileName).trim());
ps.executeQuery();
}
conn.commit();
ps.close();
ps = null;
} else {
conn.commit();
}
return v;
} catch(SQLException e) {
try {
conn.rollback();
} catch(Exception e0) { }
try {
ps.close();
ps = null;
} catch(Exception e1) { }
try {
conn.close();
conn = null;
} catch(Exception e2) { }
reCreate();
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -