由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - a Java MultiThreading question
相关主题
paint()呀,repaint()呀question on single thread & multithread
急问:怎么kill一个thread, thread.interrupte()不好用呀?如何让两个socket并行执行thread
问个HttpClient 的问题Basic thread question
怎么练习java multithreadHow to ues log4j to send log email in the multithreaded processes as similiar with single-threaded
multi-threading guru们 (转载)怎么可以练习多线程编程呢?
怎么学multithreading/concurrency?求问如何学习multithreading
Thread对应的input和output问题java concurrency (转载)
Re: Help!!! Java in Unix. Thread. I need exit and ls concurrently runnAnyone familar with ULC?
相关话题的讨论汇总
话题: java话题: main话题: thread话题: thread2
进入Java版参与讨论
1 (共1页)
r*******o
发帖数: 38
1
Thanks ahead for any solution and suggestion from you, I am not familar to
Java multithreading.
A program need to have 3 different threads, each of them will live as long as
the program,
1. Main thread, start with main() function, its function is to start following
two threads, then waiting to receive command line input from user.
2. A coordinator thread, works as a coordinator, after main thread receives a
command from user, it will send the command as a request to other machine's
participant t
r**s
发帖数: 2
2
试试看在thread2代码的开始先让他调用sleep()或者yield()

as
following
a
killed
main

【在 r*******o 的大作中提到】
: Thanks ahead for any solution and suggestion from you, I am not familar to
: Java multithreading.
: A program need to have 3 different threads, each of them will live as long as
: the program,
: 1. Main thread, start with main() function, its function is to start following
: two threads, then waiting to receive command line input from user.
: 2. A coordinator thread, works as a coordinator, after main thread receives a
: command from user, it will send the command as a request to other machine's
: participant t

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

main
What do you do in the coordinator thread (thread 2?) once it's started? If it
runs in a polling loop, yeah it'd very likely block out other threads for a
while (it can't completely "take over the execution" though).

【在 r*******o 的大作中提到】
: Thanks ahead for any solution and suggestion from you, I am not familar to
: Java multithreading.
: A program need to have 3 different threads, each of them will live as long as
: the program,
: 1. Main thread, start with main() function, its function is to start following
: two threads, then waiting to receive command line input from user.
: 2. A coordinator thread, works as a coordinator, after main thread receives a
: command from user, it will send the command as a request to other machine's
: participant t

h****r
发帖数: 2056
4
If this is the case, how to solve it?

line
it

【在 m******t 的大作中提到】
:
: main
: What do you do in the coordinator thread (thread 2?) once it's started? If it
: runs in a polling loop, yeah it'd very likely block out other threads for a
: while (it can't completely "take over the execution" though).

B******N
发帖数: 445
5
can not see the reason from pseudo code, better put the real code.
psedo code sounds reasonable. something is wrong in your thread2.

as
following
a
killed
main

【在 r*******o 的大作中提到】
: Thanks ahead for any solution and suggestion from you, I am not familar to
: Java multithreading.
: A program need to have 3 different threads, each of them will live as long as
: the program,
: 1. Main thread, start with main() function, its function is to start following
: two threads, then waiting to receive command line input from user.
: 2. A coordinator thread, works as a coordinator, after main thread receives a
: command from user, it will send the command as a request to other machine's
: participant t

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

Well the coordinator could wait on something and only get notified when there
is some message to send -- google the producer-consumer pattern.

【在 h****r 的大作中提到】
: If this is the case, how to solve it?
:
: line
: it

w*r
发帖数: 2421
7
from your psudo code, we can find nothing wrong. The problem may reside in
your run method of thread2. Thread scheduler should get a chance to interrup
the thread2 to continue execute the rest part of your main method. If your
thread2 is too heavy duty, it will take long(infinite) time for thread
scheduler to come back to the main method. For example, if your thread2's run
method is
public void run(){
while(true){
do nothing
}
}
The virtue machine will not get a chance to come back to create t

【在 r*******o 的大作中提到】
: Thanks ahead for any solution and suggestion from you, I am not familar to
: Java multithreading.
: A program need to have 3 different threads, each of them will live as long as
: the program,
: 1. Main thread, start with main() function, its function is to start following
: two threads, then waiting to receive command line input from user.
: 2. A coordinator thread, works as a coordinator, after main thread receives a
: command from user, it will send the command as a request to other machine's
: participant t

w*r
发帖数: 2421
8
From your psudo code, there is nothing run. Are you sure the thread3 is never
got created? Or it is just blocked on execution? Well, it is too vague to
juedge from your psudocode, there is nothing wrong there.

run
do
receives
machine's
programming.
to
killed

【在 w*r 的大作中提到】
: from your psudo code, we can find nothing wrong. The problem may reside in
: your run method of thread2. Thread scheduler should get a chance to interrup
: the thread2 to continue execute the rest part of your main method. If your
: thread2 is too heavy duty, it will take long(infinite) time for thread
: scheduler to come back to the main method. For example, if your thread2's run
: method is
: public void run(){
: while(true){
: do nothing
: }

1 (共1页)
进入Java版参与讨论
相关主题
Anyone familar with ULC?multi-threading guru们 (转载)
[合集] 请教: A question related to thread communication怎么学multithreading/concurrency?
Re: How to lock a file and detect a thread is over?Thread对应的input和output问题
[转载] 现在还有什么OS不是THREAD级调度的吗?Re: Help!!! Java in Unix. Thread. I need exit and ls concurrently runn
paint()呀,repaint()呀question on single thread & multithread
急问:怎么kill一个thread, thread.interrupte()不好用呀?如何让两个socket并行执行thread
问个HttpClient 的问题Basic thread question
怎么练习java multithreadHow to ues log4j to send log email in the multithreaded processes as similiar with single-threaded
相关话题的讨论汇总
话题: java话题: main话题: thread话题: thread2