站内搜索: 请输入搜索关键词

当前页面: JAVA 编程资料牛鼻论坛J2ee & 企业开发技术区→多线程检索

多线程检索

发表新主题   回复此主题

第1楼 2008-08-09 09:16 thankyou2008 写道:

多线程检索

我在一个 while循环的 多线程查询 程序 中
出现了 个问题,
ServiceThread st = new ServiceThread(url, "a web service thread");
st.start();
这个线程 没 把 自己run方法 完全 执行完,就 去 执行 这个while 循环 后面的内容去了。

.是不是可以 判断 一下,前面的创建的 线程里run方法都执行完了,,然后 再 执行 下面的 啊?怎么 判断呢?
关键代码如下:在一个while循环中每循环一次 取得 一个url地址,然后 根据 这个url地址进行 查询,我每一次查询 都启用一个线程。
while (it.hasNext()){
linkedListCell=null;
foo = (Element) it.next();

String url= foo.elementText("url") ;
url= url+"SearchForYou rvices archCell";


ServiceThread st = new ServiceThread(url, "a web service thread");
st.start();
}

.是不是可以 这个后面 来一句 判断 ,前面的线程 是否 结束了 ,然后 再 执行 下面的 啊?怎么 判断呢?

//获取结束时间
long end=System.currentTimeMillis();
//打印一下
system.out.println(end);

double intervalTime=(end-start)*0.001;

//本类 执行完之后转向 page所指向的 action类
String target = "Page";
return mapping.findForward(target);

另外我的 ServiceThread部分代码如下:
public class ServiceThread extends Thread{
private String ip; //每一个线程对象启动时要访问的ip
private String searchContent;
public ServiceThread(String ip, String str,String searchContent){
super(str);
this.ip = ip;
this.searchContent=searchContent;//传过来 的查询内容,即查询关键字。
}

public void run(){
//根据ip创建相应的web Service并通过它进行远程方法调用
String url= ip+"SearchForYou/services/SearchCell";


//构建 URL
URL aUrl = null;
try {
aUrl = new URL(url);
} catch (MalformedURLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
System.out.println("已经生成了URL");

//下面的代码 新建 web service 服务,并通过 它 进行 远程方法 调用。
Service service = new Service();
Call call = null;

System.out.println("创建了service");
try {
call = (Call) service.createCall();

} catch (ServiceException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

System.out.println("(Call) service.createCall()");

call.setTargetEndpointAddress( aUrl );


call.setOperationName("execute");


call.setEncodingStyle("UTF-8");


String linkedListStr =null;
Integer timeout= new Integer("0");


try{

linkedListStr = (String) call.invoke(new Object [] { searchContent });

call.setTimeout(timeout);

}catch(Exception e){
System.out.println(url+"连接超时,这台机子程序没有配置完全,或者网络连接有问题");
linkedListStr=null;
}
LinkedList linkedListCell=null;
if(linkedListStr!=null )linkedListCell=(LinkedList)decodeBean(linkedListStr); // 如果对方机器 传递过来的结果集--xml串不为空,则 对其进行decode处理。
System.out.println("linkedListCell=(LinkedList)decodeBean(linkedListStr)");
System.out.println(linkedListCell.size());
//把从 每一个服务器内 获取的 记录集加到内存 中的静态链表 中
if(linkedListCell!=null )GlobalUtil.resultLinkedList.addAll(linkedListCell);
System.out.println("总链表中个数"+GlobalUtil.resultLinkedList.size());

}

第2楼 2013-08-31 12:44 Robot :

多线程检索 相关


发表新主题   回复此主题