Article View: borland.public.jbuilder.java.language
Article #16920Re: how to use timer
From: Tor Iver Wilhelmsen
Date: Mon, 04 Jan 1999 00:00
Date: Mon, 04 Jan 1999 00:00
61 lines
1672 bytes
1672 bytes
Ofir Amitai <amitay@econ.haifa.ac.il> writes:
> Hi
>
> Thanx for your answer, but could u pleasegive me a more detailed example
> ?
public class Scheduler extends Thread {
private long period = 0L;
public Activity target = null; // Make accessors for this
public Scheduler(int seconds)
{
super("Scheduler");
period = seconds * 1000;
}
public synchronized void run()
{
while (true)
{
try {
if (target == null)
wait(); // Nothing to do - yet
else {
// Wake up
synchronized (target) {
target.notify();
}
Thread.sleep(period);
}
}
catch (InterruptedException ie)
{
}
}
}
}
public abstract class Activity extends Thread {
public abstract void activity();
public Activity(String name)
{
super(name);
setDaemon(true);
start();
}
public synchronized void run() {
while (true) {
try {
wait(); // Will be awakened by Scheduler
activity();
}
catch (InterruptedException ie) { }
}
}
}
Technical Details
Message-ID:
<u90fj1ba7.fsf@sds.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3690A008.C802EE4D@econ.haifa.ac.il> <u1zlbl1lc.fsf@sds.no> <3690AEC8.20B1112E@econ.haifa.ac.il>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,2f6728999b8f4dca X-Google-Attributes: gidf74b3,public From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no> Subject: Re: how to use timer Date: 1999/01/04 Message-ID: <u90fj1ba7.fsf@sds.no> X-Deja-AN: 428608586 Sender: towi@SDSA1761 References: <3690A008.C802EE4D@econ.haifa.ac.il> <u1zlbl1lc.fsf@sds.no> <3690AEC8.20B1112E@econ.haifa.ac.il> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language