Você está na página 1de 4

addantrian(); Date tgl_skrg = new Date(); long tglskrg=tgl_skrg.

getTime(); downloader[] downloaders = new downloader[n_thread];

for (int i=0; i<=n_thread-1;i++){ downloaders[i] = new downloader("thread onl "+(i+1),"set awal","set awal","set awal",0,"set awal","set awal","set awal","set awal","set awal","set awal","set awal",0,0,"set awal",cnfg); downloaders[i].start();} int masalah = 0; while( !antrian.isEmpty()) { for(int i=0; i<=n_thread-1; i++){ if(chekcon()>2){ masalah=1;break;} else if(!downloaders[i].isAlive()){ String id_,url_,file_lastmodife_ ,download_lastmodife_ ,file_size_; synchronized(this) { Object n[][] = antrian.remove(); id_ = n[0][0].toString(); url_ = n[0][1].toString(); file_lastmodife_ = (n[0][2] == null ? "1970-01-01 07:00:00" : n[0][2].toString()); download_lastmodife_ =(n[0][3] == null ? "1970-01-01 07:00:00" : n[0][3].toString()); file_size_ = n[0][4].toString(); }

System.out.println("thread onl "+(i+1)+" <-- "+url_+" sisa "+antrian.size()); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

try{ tgl_dwn = formatter.parse(download_lastmodife_); tgl_mdf = formatter.parse(file_lastmodife_); } catch (Exception e) {} tgldwn = tgl_dwn.getTime(); tglmdf = tgl_mdf.getTime();

selisidwn = (tglskrg - tgldwn)/(1000*60*60); if (tgldwn == 0){status = "insert";} else{ if (selisidwn >= Integer.valueOf(cnfg[0][0][11])){ if (tglmdf == 0){status = "update"; } else{status = "chek_mdf";} } else{status = "cheked";} } downloaders[i] = new downloader("thread onl "+ (i+1),status,id_,url_,tglmdf,Integer.toString(nilai_b),database,user_namedb,passwor ddb,host_namedb,ip_proxy,port_proxy,connect_timeout,read_timeout,user_agent,cn fg); downloaders[i].start(); }

if(antrian.isEmpty()){break;} } // ulang sebanyak thread

if (antrian.size() < 1){ try { for(int i=0; i<=n_thread-1; i++) { downloaders[i].join();} } catch (InterruptedException e) {}

try{ Thread.sleep(10000);}catch(InterruptedException e){}; if(checkitem()<1){loop();addantrian();} else{addantrian();} } if(masalah == 1){System.out.println("koneksi internet terputus");break;} try{ Thread.sleep(100);}catch(InterruptedException e){}; }//end antrian //nunggu semua thread selesai try {for(int i=0; i<=n_thread-1; i++) { downloaders[i].join();} (InterruptedException e) {} System.out.println("sisi online di non aktifkan"+nilai_a); if(masalah == 1){ try { FileWriter fout = new FileWriter("stsscon"); fout.write("1"); fout.close(); } catch

}catch (IOException e) {} }

} } }

Você também pode gostar