30 -->
31
32 <body>
33 <main role="main">
34 <div class="contentContainer">
35 <h1>AWT Threading Issues</h1>
36
37 <a id="ListenersThreads"></a>
38 <h2>Listeners and threads</h2>
39
40 Unless otherwise noted all AWT listeners are notified on the event
41 dispatch thread. It is safe to remove/add listeners from any thread
42 during dispatching, but the changes only effect subsequent notification.
43 <br>For example, if a key listeners is added from another key listener, the
44 newly added listener is only notified on subsequent key events.
45
46 <a id="Autoshutdown"></a>
47 <h2>Auto-shutdown</h2>
48
49 According to
50 <cite>The Java™ Virtual Machine Specification</cite>,
51 sections 2.17.9 and 2.19,
52 the Java virtual machine (JVM) initially starts up with a single non-daemon
53 thread, which typically calls the <code>main</code> method of some class.
54 The virtual machine terminates all its activity and exits when
55 one of two things happens:
56 <ul>
57 <li> All the threads that are not daemon threads terminate.
58 <li> Some thread invokes the <code>exit</code> method of class
59 <code>Runtime</code> or class <code>System</code>, and the exit
60 operation is permitted by the security manager.
61 </ul>
62 <p>
63 This implies that if an application doesn't start any threads itself,
64 the JVM will exit as soon as <code>main</code> terminates.
65 This is not the case, however, for a simple application
66 that creates and displays a <code>java.awt.Frame</code>:
67 <pre>
68 public static void main(String[] args) {
69 Frame frame = new Frame();
70 frame.setVisible(true);
173
174 <pre>
175 <...>
176 Runnable r = new Runnable() {
177 public void run() {
178 Object o = new Object();
179 try {
180 synchronized (o) {
181 o.wait();
182 }
183 } catch (InterruptedException ie) {
184 }
185 }
186 };
187 Thread t = new Thread(r);
188 t.setDaemon(false);
189 t.start();
190 <...>
191 </pre>
192
193 <cite>The Java™ Virtual Machine Specification</cite>
194 guarantees
195 that the JVM doesn't exit until this thread terminates.
196 </div>
197 </main>
198 </body>
199 </html>
|
30 -->
31
32 <body>
33 <main role="main">
34 <div class="contentContainer">
35 <h1>AWT Threading Issues</h1>
36
37 <a id="ListenersThreads"></a>
38 <h2>Listeners and threads</h2>
39
40 Unless otherwise noted all AWT listeners are notified on the event
41 dispatch thread. It is safe to remove/add listeners from any thread
42 during dispatching, but the changes only effect subsequent notification.
43 <br>For example, if a key listeners is added from another key listener, the
44 newly added listener is only notified on subsequent key events.
45
46 <a id="Autoshutdown"></a>
47 <h2>Auto-shutdown</h2>
48
49 According to
50 <cite>The Java Virtual Machine Specification</cite>,
51 sections 2.17.9 and 2.19,
52 the Java virtual machine (JVM) initially starts up with a single non-daemon
53 thread, which typically calls the <code>main</code> method of some class.
54 The virtual machine terminates all its activity and exits when
55 one of two things happens:
56 <ul>
57 <li> All the threads that are not daemon threads terminate.
58 <li> Some thread invokes the <code>exit</code> method of class
59 <code>Runtime</code> or class <code>System</code>, and the exit
60 operation is permitted by the security manager.
61 </ul>
62 <p>
63 This implies that if an application doesn't start any threads itself,
64 the JVM will exit as soon as <code>main</code> terminates.
65 This is not the case, however, for a simple application
66 that creates and displays a <code>java.awt.Frame</code>:
67 <pre>
68 public static void main(String[] args) {
69 Frame frame = new Frame();
70 frame.setVisible(true);
173
174 <pre>
175 <...>
176 Runnable r = new Runnable() {
177 public void run() {
178 Object o = new Object();
179 try {
180 synchronized (o) {
181 o.wait();
182 }
183 } catch (InterruptedException ie) {
184 }
185 }
186 };
187 Thread t = new Thread(r);
188 t.setDaemon(false);
189 t.start();
190 <...>
191 </pre>
192
193 <cite>The Java Virtual Machine Specification</cite>
194 guarantees
195 that the JVM doesn't exit until this thread terminates.
196 </div>
197 </main>
198 </body>
199 </html>
|