由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - java thread question
相关主题
问个多线程问题Thread对应的input和output问题
one multi-threading questionmulti-threading guru们 (转载)
paint()呀,repaint()呀多少个thread 就算不正常?
请问关于用threadPoolExecutor实现threadpool的问题?怎么学multithreading/concurrency?
请教一个多线程的问题Re: native thread 和green thread
Re: How to lock a file and detect a thread is over?Re: Client-Server and actionPerformed
[转载] 现在还有什么OS不是THREAD级调度的吗?Top Ten Errors Java Programmers Make(3)
thread independent on a single-cpu machine?Re: Why Swing is not multiple-thread safe?
相关话题的讨论汇总
话题: thread话题: user话题: saving话题: pool话题: computing
进入Java版参与讨论
1 (共1页)
d*r
发帖数: 238
1
我现在正在做一个程序,遇到个问题。
我的程序是这样的:
user输入一组数,经过计算后,存到一个文件里。
因为运算的那一步比较复杂,所以user在输入一组数之后,要等一会才能输入第二组。
但是user并不需要知道结果,所以我想用threading来解决。
main thread用来接受user的输入,另一个thread(saving thread)平时处于idel。main
thread收到user
的输入后,send给saving thread。Saving thread接到main thread的message之后,开始
计算结果。
这个过程有点像http communication。但是只发生在两个thread之间。
现在问题是:
我需要一个像message pool一类的东西来存main thread发过来的message。
如果用VC的话,可以直接调用windows message queue。
如果用java怎么办呢?又没有现成的class?是在不行就只能自己写了。
f********h
发帖数: 149
2
这不就是producer 和 consumer的问题吗?网上有很多这类的java code的。

【在 d*r 的大作中提到】
: 我现在正在做一个程序,遇到个问题。
: 我的程序是这样的:
: user输入一组数,经过计算后,存到一个文件里。
: 因为运算的那一步比较复杂,所以user在输入一组数之后,要等一会才能输入第二组。
: 但是user并不需要知道结果,所以我想用threading来解决。
: main thread用来接受user的输入,另一个thread(saving thread)平时处于idel。main
: thread收到user
: 的输入后,send给saving thread。Saving thread接到main thread的message之后,开始
: 计算结果。
: 这个过程有点像http communication。但是只发生在两个thread之间。

st
发帖数: 1685
3
a first in first out queue can solve the problem...
actually IBM tuple space(free java stuff) can be used for this... I think.
or just something in memory... :D

【在 d*r 的大作中提到】
: 我现在正在做一个程序,遇到个问题。
: 我的程序是这样的:
: user输入一组数,经过计算后,存到一个文件里。
: 因为运算的那一步比较复杂,所以user在输入一组数之后,要等一会才能输入第二组。
: 但是user并不需要知道结果,所以我想用threading来解决。
: main thread用来接受user的输入,另一个thread(saving thread)平时处于idel。main
: thread收到user
: 的输入后,send给saving thread。Saving thread接到main thread的message之后,开始
: 计算结果。
: 这个过程有点像http communication。但是只发生在两个thread之间。

g*****g
发帖数: 34805
4
To be more specific, the computing thread will process until no more data in
queue and then sleep itself. A notification will be fired when current entered
data is the only one in queue.


thread)平时处于idel。main
开始

【在 st 的大作中提到】
: a first in first out queue can solve the problem...
: actually IBM tuple space(free java stuff) can be used for this... I think.
: or just something in memory... :D

xt
发帖数: 17532
5

entered
嗯,这种活我干过很多.

【在 g*****g 的大作中提到】
: To be more specific, the computing thread will process until no more data in
: queue and then sleep itself. A notification will be fired when current entered
: data is the only one in queue.
:
: 。
: thread)平时处于idel。main
: 开始

o*******m
发帖数: 8
6
You can use the concept of conneciton pool.Of course , it is thread pool here.
1)Init
create a pool of thread for computing
create a pool of thread for saving results
Logic of you program
1)Get Data from user
2)get a thread from computing pool
3)compute
4)return computing thread and get thread from saving pool
5)save and return saving thread
As simple as this, you do not need sync between threads.



【在 d*r 的大作中提到】
: 我现在正在做一个程序,遇到个问题。
: 我的程序是这样的:
: user输入一组数,经过计算后,存到一个文件里。
: 因为运算的那一步比较复杂,所以user在输入一组数之后,要等一会才能输入第二组。
: 但是user并不需要知道结果,所以我想用threading来解决。
: main thread用来接受user的输入,另一个thread(saving thread)平时处于idel。main
: thread收到user
: 的输入后,send给saving thread。Saving thread接到main thread的message之后,开始
: 计算结果。
: 这个过程有点像http communication。但是只发生在两个thread之间。

y***i
发帖数: 279
7
This is just way too much for a simple problem. Just launch a new thread
for computing as user finishes inputing, which dies after it gets and
saves the result. This is much similar to a swing GUI, and user
clicks go.

【在 o*******m 的大作中提到】
: You can use the concept of conneciton pool.Of course , it is thread pool here.
: 1)Init
: create a pool of thread for computing
: create a pool of thread for saving results
: Logic of you program
: 1)Get Data from user
: 2)get a thread from computing pool
: 3)compute
: 4)return computing thread and get thread from saving pool
: 5)save and return saving thread

1 (共1页)
进入Java版参与讨论
相关主题
Re: Why Swing is not multiple-thread safe?请教一个多线程的问题
农民运动讲习所1. Thread and paint()Re: How to lock a file and detect a thread is over?
FrameWork of Thread application 1[转载] 现在还有什么OS不是THREAD级调度的吗?
Re: Help!!! Java in Unix. Thread. I need exit and ls concurrently runnthread independent on a single-cpu machine?
问个多线程问题Thread对应的input和output问题
one multi-threading questionmulti-threading guru们 (转载)
paint()呀,repaint()呀多少个thread 就算不正常?
请问关于用threadPoolExecutor实现threadpool的问题?怎么学multithreading/concurrency?
相关话题的讨论汇总
话题: thread话题: user话题: saving话题: pool话题: computing