?? controler.java
字號:
package gather;
import java.io.File;
import java.io.FileOutputStream;
import java.util.LinkedList;
public class controler
{
public static LinkedList URLList = new LinkedList();
public static LinkedList IMGList = new LinkedList();
public static LinkedList MissionList = new LinkedList();
public static int nThreadCount = 0;
public final static int nMaxThread = 50;
public final static int nMaxURLLink = 10000;//暫不使用
public controler()
{
}
public static void start()
{
String strlinktext = "";
boolean bsavetofile = false;
int nAutoStopSignal=0;
while (true)
{
try
{
System.out.println("---->當前的線程總數:" + nThreadCount + " ;待處理的任務數:" + controler.MissionList.size() + "[ 線程數量限制:" + nMaxThread + "]");
//-------------------------------------------------------------------------
if ((nThreadCount == 0) && (controler.MissionList.size() == 0))
{
nAutoStopSignal++;
if(nAutoStopSignal>=60)
{
System.out.println("無線程、無任務的狀態已經等待60秒,將自動停止...");
break;
}
}
if ((nThreadCount < nMaxThread))
{//控制線程的數量:必須少于nMaxThread:
strlinktext = (String) controler.MissionList.pollFirst();
if (null == strlinktext || strlinktext.length() <= 0)
{
System.out.println("待處理的任務列表是空的。");
Thread.sleep(1000);
continue;
}
strlinktext = strlinktext.toLowerCase();
System.out.println("------------------------>"+strlinktext);
if (strlinktext.endsWith(".css") || strlinktext.equals("../"))
continue;
if (strlinktext.endsWith(".jpg") || strlinktext.endsWith(".bmp") || strlinktext.endsWith(".jpeg"))
{//需要保存:到文件的鏈接:
bsavetofile = true;
//該鏈接是新的,因為列表中沒有:
//-----------------
//測試:將鏈接記錄到文件:
new File("D:\\Temp\\").mkdirs();
FileOutputStream fos = new FileOutputStream("D:\\Temp\\savetofile.txt", true);
String strfile = strlinktext + "\r\n";
fos.write(strfile.getBytes());
fos.close();
}
else
{//需要解析的:新的、待解析的、網頁鏈接:
bsavetofile = false;
//該鏈接是新的,因為列表中沒有:
controler.URLList.add(strlinktext);
//-----------------
//測試:將鏈接記錄到文件:
new File("D:\\Temp\\").mkdirs();
FileOutputStream fos = new FileOutputStream("D:\\Temp\\已處理的URL.txt", true);
String strfile = strlinktext + "\r\n";
fos.write(strfile.getBytes());
fos.close();
}
//--------------------------------------------------------------
if (strlinktext.length() > 0)
{//創建線程并開始運行:
Thread g = new gather(strlinktext, bsavetofile);
g.start();//
}
}
else
{//如果線程數量到達門限,則休息1秒:
Thread.sleep(1000);
}
}
catch (Exception e)
{
// System.out.println("ERROR: controler_start_"+e);
}
}
System.out.println("全部任務處理完畢![線程數:" + nThreadCount + " ;待處理的任務數:" + controler.MissionList.size() + "]");
}
public static void main(String[] args)
{
//運行入口:
//在此輸入種子網址:
String str = "";
try
{
str="http://desktop.xaonline.com/list.asp?category=桌面壁紙&subcategory=風光";
// str="http://www.chinatuku.com/fg/dongxuemeijing/index.htm";
// str="http://www.8825.com/6_Class.asp";
// str = "http://www.ivsky.com/";
// str = "http://www.bzkoo.com/";
// str = "http://www.mydeskcity.com/";
// str = "http://www.tuhai.org/Untitled-1.html";
// str = "http://www.ivsky.com/Photo/835/87278.html";
controler.MissionList.add(str);
controler.start();
}
catch (Exception e)
{
System.out.println("當前 nRunCount:" + gather.nRunCount);
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -