日期:2014-05-18 浏览次数:20739 次
public class DataSyncServiceImpl implements DataSyncService {
private myDao dao;
private static Object lock = new Object();
@Override
public void RelayDataSync() {
List<Thread> threads = new ArrayList<Thread>();
try{
synchronized(lock){
for(int i=0;i<){
myThread thread = new myThread(dao);
thread.start();
}
}
}catch(Exception exp){
exp.printStackTrace();
}
}
}
@Service
public class myThread extends Thread{
private myDao dao;
public myThread(){
}
public myThread(myDao dao){
this.myDao =dao;
}
public void run(){
Connection conn = null;
try{
conn = getConnection();
List<Receipt> datas = getDataFromOtherDatabase(conn);
UpdateData(datas);
}catch(Exception e){
e.printStackTrace();
}
finally{
XXX
}
}
@Transactional
private void UpdateData(List<Receipt> datas){
try{
this.myDao.DeleteData(XXX);
for(Data data : datas){
this.myDao.InsertData(data);
}
}catch(Exception e){
e.printStackTrace();
}
}
}