由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Follow up Re: Simp question on
相关主题
Simp question on thread synchronizationBasic thread question
Re: Simp question on thread synchronizat问个多线程的问题。
如何让两个socket并行执行threadHow to ues log4j to send log email in the multithreaded processes as similiar with single-threaded
怎么练习java multithreadjava multithreading常识一问
Re: Help!!! Java in Unix. Thread. I need exit and ls concurrently runn求推荐的java多线程教程
question on single thread & multithreada fun coding question
如何快速处理上万个文件?multi-threading guru们 (转载)
a Java MultiThreading question我觉得新手应该系统学学基本知识
相关话题的讨论汇总
话题: tracktime话题: client话题: simp话题: follow
进入Java版参与讨论
1 (共1页)
g****n
发帖数: 18
1
At first, thanks to everyone who helped me out on the previous question.
Now I encounter a new problem. The code is listed below for the convenience
while (listening)
{
System.out.println("Waiting for a client...");
MultiThread mthread = new MultiThread(group, serverSocket.accept(), h);
mthread.start;
mthread.join();
trackTime = h.getTime();
System.out.println("Track time " + trackTime);
System.out.println("Load: " + group.activeCount
xt
发帖数: 17532
2

It looks this piece of code really defeats the purpose of multithread
programming.
mthread can't be run for twice. Most probably it is this piece of code that is
run twice (or going for 2 loop runs) for some reason.

【在 g****n 的大作中提到】
: At first, thanks to everyone who helped me out on the previous question.
: Now I encounter a new problem. The code is listed below for the convenience
: while (listening)
: {
: System.out.println("Waiting for a client...");
: MultiThread mthread = new MultiThread(group, serverSocket.accept(), h);
: mthread.start;
: mthread.join();
: trackTime = h.getTime();
: System.out.println("Track time " + trackTime);

m******t
发帖数: 2416
3

Why don't you make MultiThread keep track of how much time it took itself,
instead of having the server thread do it - it's not really the server
thread's job.

【在 g****n 的大作中提到】
: At first, thanks to everyone who helped me out on the previous question.
: Now I encounter a new problem. The code is listed below for the convenience
: while (listening)
: {
: System.out.println("Waiting for a client...");
: MultiThread mthread = new MultiThread(group, serverSocket.accept(), h);
: mthread.start;
: mthread.join();
: trackTime = h.getTime();
: System.out.println("Track time " + trackTime);

c****e
发帖数: 90
4
真是不明白你的代码,不明白你要干吗?
你既然同时要处理多个client,
头一个client连接,你启动一个线程MultiThread去处理他
然后调用join就等那个线程结束
那个线程结束后你计时 (这是什么时间?处理完头一个client后当前系统时间?)
假如在头一个client没有处理完的时候,第二个client来了
这是主线程在等待中(join) 不能处理
直到头一个client完成,MultiThread结束,join 才能返回
如果这时候第二个client还在连接当中,才会被下一个MutiThread处理。
用了join, 让你的多线程一点意义都没有,根本没有并行度,只能一个一个
client的顺序处理。
不用join ,那个计时计下的是什么时间? 在client很少的情况下
accept会block, 记下的是client到来的时间。
在client很密集的时候记下的是java 打印三行message,new并启动一个
进程, 取系统时钟再加loop overhead的时间。
你为什么不在MultiThread.run() 开始和返回之前计时?相减不就是
处理一个clie

【在 g****n 的大作中提到】
: At first, thanks to everyone who helped me out on the previous question.
: Now I encounter a new problem. The code is listed below for the convenience
: while (listening)
: {
: System.out.println("Waiting for a client...");
: MultiThread mthread = new MultiThread(group, serverSocket.accept(), h);
: mthread.start;
: mthread.join();
: trackTime = h.getTime();
: System.out.println("Track time " + trackTime);

1 (共1页)
进入Java版参与讨论
相关主题
我觉得新手应该系统学学基本知识Re: Help!!! Java in Unix. Thread. I need exit and ls concurrently runn
CC150 16.6答案是不是有问题? (转载)question on single thread & multithread
怎么可以练习多线程编程呢?如何快速处理上万个文件?
anyone using play framework (from Typesafe)?a Java MultiThreading question
Simp question on thread synchronizationBasic thread question
Re: Simp question on thread synchronizat问个多线程的问题。
如何让两个socket并行执行threadHow to ues log4j to send log email in the multithreaded processes as similiar with single-threaded
怎么练习java multithreadjava multithreading常识一问
相关话题的讨论汇总
话题: tracktime话题: client话题: simp话题: follow