A*o
4 楼
public static void main(String[] args){
new Timer().schdule(new MyTimerTask(), new Date());
}
为什么程序不能正常推出呢?
new Timer().schdule(new MyTimerTask(), new Date());
}
为什么程序不能正常推出呢?
A*o
5 楼
如果
public static void main(String[] args){
new Timer(true).schdule(new MyTimerTask(), new Date());
Thread.sleep(2000);
}
就可以了。
public static void main(String[] args){
new Timer(true).schdule(new MyTimerTask(), new Date());
Thread.sleep(2000);
}
就可以了。
h*g
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
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
9 楼
搞得很复杂的说。
object
one
restart
【在 h*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 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
object
one
restart
【在 h*****g 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 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
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 的大作中提到】![](/moin_static193/solenoid/img/up.png)
:
: Did you try:
: new Timer(true).schdule(new MyTimerTask(), new Date());
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 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
:
: Did you try:
: new Timer(true).schdule(new MyTimerTask(), new Date());
m*t
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 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 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.
相关阅读
ant junit and log4j can't work togetherHow to compute round-trip time to webser[转载] 有人成功在mandrake9.1下面装过....Re: Custom Tag: embedding tag inside tagGenerating Java code in SCRWhich IDE is good in Linux?A question of Netbeans问个简单问题Swing help这个方法到底如何调用的?菜鸟问题[转载] Re: 觉得自己很笨请问java有办法隐藏source code吗AWT tooltip?Any good project documentation tools (free?)Authenticated Applet Doesn't Show in VBAppCracked JProbe?JDBC & Firewallsocket and simple web browserBuild web server and dispatcher?