01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.lang.management;
19:
20: /**
21: * A thread hooked as a VM shutdown hook to tell a MemoryNotificationThread to
22: * terminate.
23: *
24: * @since 1.5
25: */
26: class MemoryNotificationThreadShutdown extends Thread {
27: private MemoryNotificationThread myVictim;
28:
29: /**
30: * Basic constructor
31: *
32: * @param victim
33: * The thread to notify on shutdown
34: */
35: MemoryNotificationThreadShutdown(MemoryNotificationThread victim) {
36: myVictim = victim;
37: }
38:
39: /**
40: * Shutdown hook code that coordinates the termination of a memory
41: * notification thread.
42: */
43: public void run() {
44: sendShutdownNotification(myVictim.internalID);
45: try {
46: // wait for the notification thread to terminate
47: myVictim.join();
48: } catch (InterruptedException e) {
49: // don't care
50: }
51: }
52:
53: /**
54: * Wipes any pending notifications and puts a shutdown request notification
55: * on an internal notification queue.
56: *
57: * @param id
58: * The internal id of the queue to shut down
59: */
60: private native void sendShutdownNotification(int id);
61: }
|