由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 这个Timer不退出是怎么回事儿?
相关主题
Timer and TimerTask问个Thread 的问题,java certificate里的
简单的schedule job, 你们用什么question on single thread & multithread
Why System.currentTimeMillis() is later then TimerTask.scheduledExecutionTime() in some cases?有关thread in Java
java.util.timer的TimerTask有priority吗?线程问题。
问一个lock的puzzle线程hardy会一直等待下去么?
如何让两个socket并行执行thread一道java题
急问:怎么kill一个thread, thread.interrupte()不好用呀?htmlunit及多线程问题
很简单的代码,问题求助。太迷惑了web app 每天更新数据一次
相关话题的讨论汇总
话题: timer话题: thread话题: new话题: date
进入Java版参与讨论
1 (共1页)
A**o
发帖数: 1550
1
为什么明明TimerTask已经结束了,但是那个thread还来在那里不退出?
有人给解释一下么?
t****r
发帖数: 25
2
what ur code look like??

【在 A**o 的大作中提到】
: 为什么明明TimerTask已经结束了,但是那个thread还来在那里不退出?
: 有人给解释一下么?

l****u
发帖数: 2166
3
details too little ya

【在 A**o 的大作中提到】
: 为什么明明TimerTask已经结束了,但是那个thread还来在那里不退出?
: 有人给解释一下么?

A**o
发帖数: 1550
4
public static void main(String[] args){
new Timer().schdule(new MyTimerTask(), new Date());
}
为什么程序不能正常推出呢?
A**o
发帖数: 1550
5
如果
public static void main(String[] args){
new Timer(true).schdule(new MyTimerTask(), new Date());
Thread.sleep(2000);
}
就可以了。
t****r
发帖数: 25
6
i guess if it's a non-daemon thread, it does not need to stop right away.

【在 A**o 的大作中提到】
: 如果
: public static void main(String[] args){
: new Timer(true).schdule(new MyTimerTask(), new Date());
: Thread.sleep(2000);
: }
: 就可以了。

A**o
发帖数: 1550
7
yeah. that's what java api doc says.
i just want to know the reason behind it. :p

【在 t****r 的大作中提到】
: i guess if it's a non-daemon thread, it does not need to stop right away.
h*****g
发帖数: 1
8
Once a thread is done, u can not call the start method of the thread object
to rerun it.
Timer is usually used to run the task over and over again during some time
intervals, and it can be shared by multiple threads. finishing task with one
thread doesn't mean the timer thread won't be used by other thread. there
is no good way to tell that if there is a live thread will use it in the
future.
The design can help you save the cost and overhead to terminate and restart
a new timer thread if ever u
A**o
发帖数: 1550
9
搞得很复杂的说。

object
one
restart

【在 h*****g 的大作中提到】
: Once a thread is done, u can not call the start method of the thread object
: to rerun it.
: Timer is usually used to run the task over and over again during some time
: intervals, and it can be shared by multiple threads. finishing task with one
: thread doesn't mean the timer thread won't be used by other thread. there
: is no good way to tell that if there is a live thread will use it in the
: future.
: The design can help you save the cost and overhead to terminate and restart
: a new timer thread if ever u

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

Did you try:
new Timer(true).schdule(new MyTimerTask(), new Date());

【在 A**o 的大作中提到】
: public static void main(String[] args){
: new Timer().schdule(new MyTimerTask(), new Date());
: }
: 为什么程序不能正常推出呢?

A**o
发帖数: 1550
11
yes, then the timer dies as the main thread dies, instantly.
i'd expect timer dies after its completion.
and so did the whole applicaiton shuts down as no timer is pending.
well, anyway, it was a special requirement.

【在 m******t 的大作中提到】
:
: Did you try:
: new Timer(true).schdule(new MyTimerTask(), new Date());

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

I would still try making the timer itself a daemon, and spawn a non-daemon
thread in the timer task to do the actual work.

【在 A**o 的大作中提到】
: yes, then the timer dies as the main thread dies, instantly.
: i'd expect timer dies after its completion.
: and so did the whole applicaiton shuts down as no timer is pending.
: well, anyway, it was a special requirement.

1 (共1页)
进入Java版参与讨论
相关主题
web app 每天更新数据一次问一个lock的puzzle
Re: How to lock a file and detect a thread is over?如何让两个socket并行执行thread
[转载] 现在还有什么OS不是THREAD级调度的吗?急问:怎么kill一个thread, thread.interrupte()不好用呀?
java thread question很简单的代码,问题求助。太迷惑了
Timer and TimerTask问个Thread 的问题,java certificate里的
简单的schedule job, 你们用什么question on single thread & multithread
Why System.currentTimeMillis() is later then TimerTask.scheduledExecutionTime() in some cases?有关thread in Java
java.util.timer的TimerTask有priority吗?线程问题。
相关话题的讨论汇总
话题: timer话题: thread话题: new话题: date