由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - java 程序中的实时控制
相关主题
请教:怎么把synchronize的method改成用thread 但thread safe呢?如何让两个socket并行执行thread
新手问个multi-threading关于synchronized和volatile的问题Suggestion Re: 发现 synchronized 的一个问题
Re: How to lock a file and detect a thread is over?另一个入门问题。
multi-threading guru们 (转载)java ,wait ,notify notifyall
Apply lock on a class.Java synchronized method一问
问一个基础问题How to make code thread-safe?应该怎么答?
Java concurrency的疑惑,难道我理解错了? (转载)new thread object 占的是heap还是stack?
[转载] 现在还有什么OS不是THREAD级调度的吗?Re: Question: Java Synchronization
相关话题的讨论汇总
话题: thread话题: call话题: java话题: variable话题: 调用
进入Java版参与讨论
1 (共1页)
a***t
发帖数: 12
1
在java程序中, 比如要调用一个system call, 但是不能确定这个
system call 什么时候才能返回, java程序如何控制system call的
调用时间?
Process p = Runtime.getRuntime().exec(commandLine);
// 调用外部程序
如果调用五秒钟还没有返回,就要放弃这个调用, 夺回程序控制
权该如何夺回?
多谢多谢。
g*****g
发帖数: 34805
2
Launch a thread to do the job, main thread will sleep 5 seconds, then
wake up and kill the system call.
if the job is done in less than 5 seconds, you can wake up main thread.

【在 a***t 的大作中提到】
: 在java程序中, 比如要调用一个system call, 但是不能确定这个
: system call 什么时候才能返回, java程序如何控制system call的
: 调用时间?
: Process p = Runtime.getRuntime().exec(commandLine);
: // 调用外部程序
: 如果调用五秒钟还没有返回,就要放弃这个调用, 夺回程序控制
: 权该如何夺回?
: 多谢多谢。

t**s
发帖数: 22
3
严格地说一个Thread不能中止另外一个Thread。如果那个System Call是
Synchronize的Call的话,从Java内部无法中止。

【在 g*****g 的大作中提到】
: Launch a thread to do the job, main thread will sleep 5 seconds, then
: wake up and kill the system call.
: if the job is done in less than 5 seconds, you can wake up main thread.

c*y
发帖数: 137
4
Depends on what you mean by "terminate a thread from another thread". You can
surely not directly call anything like "destroy()" to destroy that method. But
you can always have a flag variable (e.g., cancelled) and a public function
which can change this flag variable, make the flag variable false when the
thread starts, and check this variable while running the thread. And if you
want to terminate the thread from another thread, just set the flag variable
to be true from the main thread.

【在 t**s 的大作中提到】
: 严格地说一个Thread不能中止另外一个Thread。如果那个System Call是
: Synchronize的Call的话,从Java内部无法中止。

t*******k
发帖数: 20
5
It may not work if you want to terminate the call in precisely 5 seconds.
In realtime Java, you might be able to set deadline.

【在 c*y 的大作中提到】
: Depends on what you mean by "terminate a thread from another thread". You can
: surely not directly call anything like "destroy()" to destroy that method. But
: you can always have a flag variable (e.g., cancelled) and a public function
: which can change this flag variable, make the flag variable false when the
: thread starts, and check this variable while running the thread. And if you
: want to terminate the thread from another thread, just set the flag variable
: to be true from the main thread.

1 (共1页)
进入Java版参与讨论
相关主题
Re: Question: Java SynchronizationApply lock on a class.
Re: Java里怎么调用unix下的command?问一个基础问题
Java Http Question?Java concurrency的疑惑,难道我理解错了? (转载)
java socket 问题[转载] 现在还有什么OS不是THREAD级调度的吗?
请教:怎么把synchronize的method改成用thread 但thread safe呢?如何让两个socket并行执行thread
新手问个multi-threading关于synchronized和volatile的问题Suggestion Re: 发现 synchronized 的一个问题
Re: How to lock a file and detect a thread is over?另一个入门问题。
multi-threading guru们 (转载)java ,wait ,notify notifyall
相关话题的讨论汇总
话题: thread话题: call话题: java话题: variable话题: 调用