订阅所有JSP/Servlet的日志 订阅 | 这是最新一篇日志 上一篇 | 下一篇日志 下一篇 ]
JAVA技术

addShutdownHook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
     * Registers a new virtual-machine shutdown hook.
     *
     * <p> The Java virtual machine <i>shuts down</i> in response to two kinds
     * of events:
     *
     *   <ul>
     *
     *   <p> <li> The program <i>exits</i> normally, when the last non-daemon
     *   thread exits or when the <tt>{@link #exit exit}</tt> (equivalently,
     *   <tt>{@link System#exit(int) System.exit}</tt>) method is invoked, or
     *
     *   <p> <li> The virtual machine is <i>terminated</i> in response to a
     *   user interrupt, such as typing <tt>^C</tt>, or a system-wide event,
     *   such as user logoff or system shutdown.
     *
     *   </ul>
     *
     * <p> A <i>shutdown hook</i> is simply an initialized but unstarted
     * thread.  When the virtual machine begins its shutdown sequence it will
     * start all registered shutdown hooks in some unspecified order and let
     * them run concurrently.  When all the hooks have finished it will then
     * run all uninvoked finalizers if finalization-on-exit has been enabled.
     * Finally, the virtual machine will halt.  Note that daemon threads will
     * continue to run during the shutdown sequence, as will non-daemon threads
     * if shutdown was initiated by invoking the <tt>{@link #exit exit}</tt>
     * method.
     *
     * <p> Once the shutdown sequence has begun it can be stopped only by
     * invoking the <tt>{@link #halt halt}</tt> method, which forcibly
     * terminates the virtual machine.
     *
     * <p> Once the shutdown sequence has begun it is impossible to register a
     * new shutdown hook or de-register a previously-registered hook.
     * Attempting either of these operations will cause an
     * <tt>{@link IllegalStateException}</tt> to be thrown.
     *
     * <p> Shutdown hooks run at a delicate time in the life cycle of a virtual
     * machine and should therefore be coded defensively.  They should, in
     * particular, be written to be thread-safe and to avoid deadlocks insofar
     * as possible.  They should also not rely blindly upon services that may
     * have registered their own shutdown hooks and therefore may themselves in
     * the process of shutting down.
     *
     * <p> Shutdown hooks should also finish their work quickly.  When a
     * program invokes <tt>{@link #exit exit}</tt> the expectation is
     * that the virtual machine will promptly shut down and exit.  When the
     * virtual machine is terminated due to user logoff or system shutdown the
     * underlying operating system may only allow a fixed amount of time in
     * which to shut down and exit.  It is therefore inadvisable to attempt any
     * user interaction or to perform a long-running computation in a shutdown
     * hook.
     *
     * <p> Uncaught exceptions are handled in shutdown hooks just as in any
     * other thread, by invoking the <tt>{@link ThreadGroup#uncaughtException
     * uncaughtException}</tt> method of the thread's <tt>{@link
     * ThreadGroup}</tt> object.  The default implementation of this method
     * prints the exception's stack trace to <tt>{@link System#err}</tt> and
     * terminates the thread; it does not cause the virtual machine to exit or
     * halt.
     *
     * <p> In rare circumstances the virtual machine may <i>abort</i>, that is,
     * stop running without shutting down cleanly.  This occurs when the
     * virtual machine is terminated externally, for example with the
     * <tt>SIGKILL</tt> signal on Unix or the <tt>TerminateProcess</tt> call on
     * Microsoft Windows.  The virtual machine may also abort if a native method goes awry
     * by, for example, corrupting internal data structures or attempting to
     * access nonexistent memory.  If the virtual machine aborts then no
     * guarantee can be made about whether or not any shutdown hooks will be
     * run. <p>
     *
     * @param   hook
     *          An initialized but unstarted <tt>{@link Thread}</tt> object
     *
     * @throws  IllegalArgumentException
     *          If the specified hook has already been registered,
     *          or if it can be determined that the hook is already running or
     *          has already been run
     *
     * @throws  IllegalStateException
     *          If the virtual machine is already in the process
     *          of shutting down
     *
     * @throws  SecurityException
     *          If a security manager is present and it denies
     *          <tt>{@link RuntimePermission}("shutdownHooks")</tt>
     *
     * @see #removeShutdownHook
     * @see #halt(int)
     * @see #exit(int)
     * @since 1.3
     */
    public void addShutdownHook(Thread hook) {
	SecurityManager sm = System.getSecurityManager();
	if (sm != null) {
	    sm.checkPermission(new RuntimePermission("shutdownHooks"));
	}
	Shutdown.add(hook);
    }


平均得分
(0 次评分)





文章来自: 本站原创
标签: Virtual shutdown machine exit 
评论: 19 | 查看次数: 2476
  • 共有 19 条评论
  • 1
  • 2
  • |
  • >>
yanlink [2010-07-29 14:05:36]
gucci [2010-05-19 16:20:52]
uggbootscheap [2010-05-06 19:00:51]
I do not know who wrote those nike running shoes words, but I have always liked them as a reminder that the future can be anything we want to make nike air max 95 it. We can take the mysterious, hazy future and carve out of it anything that we can nike 97 air max imagine, just like a sculptor carves a statue from a shapeless stone. We are all in the position of the farmer. If we plant a good nike 360 running shoes seed, we reap a good harvest. If our seed is poor and full of weeds, we reap a useless crop. If we plant nothing timberland shoes store at all, we harvest nothing at all. I want the future to be better than the past. I don't want it contaminated by the mistakes and cheap timberland boots errors with which history is filled. We should all be concerned about the future because that is where we will spend the reminder of our nike puma shoes lives. 06 May LH
uggbootscheap [2010-05-03 20:00:56]
Ravello is a town which has served jimmy choo handbags historically as a destination for artists, musicians and writers, such as Richard Wagner, Virginia Woolf, Gore Vidal and Sara Teasdale who mentioned the fascinating chanel black bag town in her prefatory dedication in Love Songs, one of her many books of poems. Today the peaceful historical town has become the most popular mulberry messenger bag destination for tourists and honeymooners for its enchanting views, gardens and classical music concerts. As cheap prada handbags said, the wonderful things always excite the fountain of inspiration, thus the designers from louis vuitton damier geant created the stylish damier canvas ravello miu miu handbag replica. 03 May LH
beeflee [2009-10-13 12:42:01]
beeflee [2009-05-04 19:54:14]
游客 [2009-01-09 17:10:41]
游客 [2008-12-30 15:07:20]
术+术:可能是唯一有可能冲上2300的同职业组合,天赋一般选用双恶魔法+贼:控制+爆发型,法师的爆发力略胜术士,不过容错性非常小,游戏相似组合还有法+野D,法+暗牧法+法:双冰法控制,综合来说还不错,续战力也存活能力也很强。双奥法的秒杀流一经提出就被喷的面目全非,我本人其实尝试过这个组合,可惜装备只有S2,法伤最多也只能撑到102X(现在能高不少),魔兽队友情况也差不多。这样的组合容错性低的离谱,虽然有10000+HP 400+韧性,但是感觉一被打就瞬间死,而且跑还跑不掉,所以这个打法还是更适合高端副本装,反正一样死很快。组合上还是克死战士队,别和我提盾反,网络游戏那么明显的动画效果能吸到个火冲不错了。网游基本上能够硬顶过我们5秒的职业只有骑士,冰法,盗贼和恶魔SS了。打盗贼队伍,如果是盗贼+看的见,一律先把看的见的OOXX了,双盗贼很难打,2斗篷我们免费网络游戏直接去一人。最后被一个队恶魔SS+骑士卡住了,因为奥法的后续爆发几乎没有,开局秒恶魔SS和骑士都不成功。感觉装备足够猛的话,2000是没问题的,2000以后看能否连好沉默来秒SS了。法伤最好是NOBUFF 1200+以上,最新网游保证秒杀的成功率,可以不用考虑血和韧性,建议装备牛B的法师们平时娱乐使用,非常畅快的战斗贼+暗牧:爆发力非常强的组合,而且他们的视频里很不厚道的最新免费网络游戏吃了金童3场贼+野D:第一赛季闷+盲+消失补闷+飓风的完美控制秒杀型队伍,不过在徽章能解所有控制技能之后容错性大大降低了。
游客 [2008-12-19 15:42:55]
游客 [2008-12-05 16:16:49]
东大主打产品板链流水线、仪器仪表装配生产线设备;也可根据客户的实际需要进行对口适应性的设计制造。
游客 [2008-10-25 22:03:07]
游客 [2008-10-16 08:16:00]
游客 [2008-10-06 14:06:48]
游客 [2008-09-28 10:31:11]
游客 [2008-09-03 18:47:41]
  • 共有 19 条评论
  • 1
  • 2
  • |
  • >>
发表评论
昵 称:  登录
内 容:
选 项:
字数限制 1000 字 | UBB代码 开启 | [img]标签 开启