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: * @author Michael Danilov, Pavel Dolgov
19: * @version $Revision$
20: */package org.apache.harmony.awt.wtk;
21:
22: import org.apache.harmony.awt.internal.nls.Messages;
23:
24: public final class ShutdownThread extends Thread {
25:
26: public static final class Watchdog {
27: }
28:
29: public ShutdownThread() {
30: setName("AWT-Shutdown"); //$NON-NLS-1$
31: setDaemon(false);
32: }
33:
34: private boolean shouldStop = false;
35:
36: @Override
37: public void run() {
38: synchronized (this ) {
39: notifyAll(); // synchronize the startup
40:
41: while (true) {
42: try {
43: wait();
44: } catch (InterruptedException e) {
45: }
46:
47: if (shouldStop) {
48: notifyAll(); // synchronize the shutdown
49: return;
50: }
51: }
52: }
53: }
54:
55: @Override
56: public void start() {
57: synchronized (this ) {
58: super .start();
59: try {
60: wait();
61: } catch (InterruptedException e) {
62: // awt.26=Shutdown thread was interrupted while starting
63: throw new RuntimeException(Messages.getString("awt.26")); //$NON-NLS-1$
64: }
65: }
66: }
67:
68: public void shutdown() {
69: synchronized (this ) {
70: shouldStop = true;
71: notifyAll();
72: try {
73: wait();
74: } catch (InterruptedException e) {
75: // awt.27=Shutdown thread was interrupted while stopping
76: throw new RuntimeException(Messages.getString("awt.27")); //$NON-NLS-1$
77: }
78: }
79: }
80: }
|