|
Last change
on this file since 1392 was 2, checked in by bird, 23 years ago |
|
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
|
File size:
903 bytes
|
| Line | |
|---|
| 1 | // Test basic thread creation and wait/notify functionality.
|
|---|
| 2 | // Origin: Bryce McKinlay <[email protected]>
|
|---|
| 3 |
|
|---|
| 4 | public class Thread_Wait implements Runnable
|
|---|
| 5 | {
|
|---|
| 6 | public static void main(String args[])
|
|---|
| 7 | {
|
|---|
| 8 | new Thread_Wait();
|
|---|
| 9 | }
|
|---|
| 10 |
|
|---|
| 11 | public Thread_Wait()
|
|---|
| 12 | {
|
|---|
| 13 | System.out.println("creating thread");
|
|---|
| 14 | Thread t = new Thread(this);
|
|---|
| 15 | t.start();
|
|---|
| 16 |
|
|---|
| 17 | try
|
|---|
| 18 | {
|
|---|
| 19 | Thread.sleep(100);
|
|---|
| 20 | }
|
|---|
| 21 | catch (Exception x)
|
|---|
| 22 | {
|
|---|
| 23 | System.out.println("exception occurred: " + x);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | synchronized (this)
|
|---|
| 27 | {
|
|---|
| 28 | System.out.println("notifying other thread");
|
|---|
| 29 | notify();
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | public void run()
|
|---|
| 34 | {
|
|---|
| 35 | System.out.println ("new thread running");
|
|---|
| 36 | synchronized (this)
|
|---|
| 37 | {
|
|---|
| 38 | try
|
|---|
| 39 | {
|
|---|
| 40 | wait();
|
|---|
| 41 | }
|
|---|
| 42 | catch (Exception x)
|
|---|
| 43 | {
|
|---|
| 44 | System.out.println("exception occurred: " + x);
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | System.out.println ("thread notified okay");
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.