由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 好虫,exploit等大牛请进--关于htmlunit
相关主题
ZT: 关于性爱的多线程问题研究(一)Re: How to showStatus in Applet?
问个Thread 的问题,java certificate里的FrameWork of Thread application 1
能这么 create thread 吗?Re: connection pool
implements runable 和 extends thread●●●●紧急求助JAVA初级问题,今天project due●●●●
线程问题。Can Java thread return a value?
htmlunit中的classpath问题,总是找不到package几个问题
can applet implements runnable?一个基本问题。
java multi-threading issue比较tricky关于inner class的继承
相关话题的讨论汇总
话题: webclient话题: xinventory话题: thread话题: processing
进入Java版参与讨论
1 (共1页)
b******d
发帖数: 794
1
请问怎么多线程调用webclient
我这么写了个,结果一new webclient就退出,连exception都没有,死得干干净净。
public class XInventory implements Runnable {
@Test
public void testMultiThSearch(){
XInventory bbInv = new XInventory();

for(int i=0; i<2; i++){
new Thread(bbInv).start();
}
}

public void run(){
checkWSThread1();

}

private void checkWSThread1(){
System.out.println("processing");
WebClient webClient = new WebClient();
System.out.println("processing finished");
webClient.closeAllWindows();
}
}
输出结果是
processing
processing
r*****l
发帖数: 2859
2
Your main thread died before the two spawned threads had chance to finish.
1, Simple but not good solution: add a delay in the main thread (the test
method).
2, Better solution: add some logic to tracking spawned threads and then
finish the test. For example, each thread increments a global counter in its
finally block and test method checks the counter.

【在 b******d 的大作中提到】
: 请问怎么多线程调用webclient
: 我这么写了个,结果一new webclient就退出,连exception都没有,死得干干净净。
: public class XInventory implements Runnable {
: @Test
: public void testMultiThSearch(){
: XInventory bbInv = new XInventory();
:
: for(int i=0; i<2; i++){
: new Thread(bbInv).start();
: }

b******d
发帖数: 794
3
谢谢真牛牛大虾,搞定了。

its

【在 r*****l 的大作中提到】
: Your main thread died before the two spawned threads had chance to finish.
: 1, Simple but not good solution: add a delay in the main thread (the test
: method).
: 2, Better solution: add some logic to tracking spawned threads and then
: finish the test. For example, each thread increments a global counter in its
: finally block and test method checks the counter.

M***r
发帖数: 79
4
realBull already told you the issue. But the solution is right under you
feet. The CountDownLatch is the one specifically designed to solve this kind
of issue in Java. Here is an example: http://www.java2s.com/Code/Java/Threads/AnexampleofCountDownLatch.htm
b******d
发帖数: 794
5
谢谢阿,今天真是大牛云集阿

kind

【在 M***r 的大作中提到】
: realBull already told you the issue. But the solution is right under you
: feet. The CountDownLatch is the one specifically designed to solve this kind
: of issue in Java. Here is an example: http://www.java2s.com/Code/Java/Threads/AnexampleofCountDownLatch.htm

w**z
发帖数: 8232
6
use threadpoolexecutor, returning future .

【在 b******d 的大作中提到】
: 请问怎么多线程调用webclient
: 我这么写了个,结果一new webclient就退出,连exception都没有,死得干干净净。
: public class XInventory implements Runnable {
: @Test
: public void testMultiThSearch(){
: XInventory bbInv = new XInventory();
:
: for(int i=0; i<2; i++){
: new Thread(bbInv).start();
: }

e*****t
发帖数: 1005
7
realBull says it.
btw, junit or testng can run tests in parallel. So there's no point to spawn
your own thread. You don't need to implements Runnable, just have two metho
ds which call checkWSThread1() (you may want to rename it) and annotate them
with @Test.

its

【在 r*****l 的大作中提到】
: Your main thread died before the two spawned threads had chance to finish.
: 1, Simple but not good solution: add a delay in the main thread (the test
: method).
: 2, Better solution: add some logic to tracking spawned threads and then
: finish the test. For example, each thread increments a global counter in its
: finally block and test method checks the counter.

b******d
发帖数: 794
8
thx for the points, but i need real multi-thread. 10+ threads with different
parameters that are easy to generate within one method. I will also need to
call these multi-thread methods from outside to increase the productivity n
ot just to speed up the test, so i can't use the parallel testing.
anyway, that's a nice feature to have, and will definitely use it to test
thread safety.
thanks,

spawn
metho
them

【在 e*****t 的大作中提到】
: realBull says it.
: btw, junit or testng can run tests in parallel. So there's no point to spawn
: your own thread. You don't need to implements Runnable, just have two metho
: ds which call checkWSThread1() (you may want to rename it) and annotate them
: with @Test.
:
: its

g*****g
发帖数: 34805
9
Use a CountDownLatch, that's designed for this scenario.

its

【在 r*****l 的大作中提到】
: Your main thread died before the two spawned threads had chance to finish.
: 1, Simple but not good solution: add a delay in the main thread (the test
: method).
: 2, Better solution: add some logic to tracking spawned threads and then
: finish the test. For example, each thread increments a global counter in its
: finally block and test method checks the counter.

1 (共1页)
进入Java版参与讨论
相关主题
关于inner class的继承线程问题。
java的接口runnablehtmlunit中的classpath问题,总是找不到package
另一个入门问题。can applet implements runnable?
请问关于用threadPoolExecutor实现threadpool的问题?java multi-threading issue比较tricky
ZT: 关于性爱的多线程问题研究(一)Re: How to showStatus in Applet?
问个Thread 的问题,java certificate里的FrameWork of Thread application 1
能这么 create thread 吗?Re: connection pool
implements runable 和 extends thread●●●●紧急求助JAVA初级问题,今天project due●●●●
相关话题的讨论汇总
话题: webclient话题: xinventory话题: thread话题: processing