Article View: borland.public.jbuilder.java.language
Article #7410Re: Fun with threads
From: Yonatan Taub
Date: Thu, 21 Jun 2001 18:22
Date: Thu, 21 Jun 2001 18:22
66 lines
2024 bytes
2024 bytes
class DoSomeWorkThread extends Thread {
Object lock;
public DoSomeWorkThread(Object lock) { this.lock = lock; }
public void run() {
// simulate some lenghy calculations.
System.out.println("in worker thread - about to do some lengthy
operation.");
try { sleep(4000); }
catch(Exception x) {}
System.out.println("Finished processing and about to notify main
thread.");
synchronized(lock) {
lock.notify();
}
}
} // end class DoSomeWork
public class MainWait {
public static Object lock = new Object();
public static void main(String[] args) {
Thread t = new DoSomeWorkThread(lock);
t.start();
synchronized(lock) {
try {
System.out.println("main thread is about to wait.");
lock.wait();
} catch(InterruptedException x) {}
}
System.out.println("Main thread has been notified and can do some
finishing stuff.");
}
} // end class MainWait
Technical Details
Message-ID:
<3b322cbc$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnewsReferences:
<3b320ce8_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,2fd1c7b03719c733 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-06-21 10:36:23 PST From: "Yonatan Taub" <yonatanta@bashan.co.il> Newsgroups: borland.public.jbuilder.java.language References: <3b320ce8_1@dnews> Subject: Re: Fun with threads Date: Thu, 21 Jun 2001 20:22:55 +0200 Lines: 69 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 212.179.22.2 Message-ID: <3b322cbc$1_1@dnews> X-Trace: dnews 993143996 212.179.22.2 (21 Jun 2001 10:19:56 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnews