I have an applet with a tiled background. On that background
I draw two light spots, which take quite some time to render.
So whenever the applet (actually a Frame in my applet) is
resized I draw the tiles (this doesn't take long) and after
that would like to fire off a background thread which would
calculate the light spots:
class RenderThread extends Thread
{
public volatile boolean running = false;
public RenderThread() {
setPriority(Thread.MIN_PRIORITY);
}
public void start() {
running = true;
super.start();
}
public void run() {
while (running) {
// rendering code
}
}
}
And in my applet/frame code I call:
void init() {
thread = new RenderThread();
}
public void resize(int w, int h) {
if (thread.isAlive()) {
thread.running = false;
try {
thread.join();
} catch (Exception ex) {
ex.printStackTrace();
}
}
// draw the tiles here (that is quick)
super.setSize(w, h);
thread.start();
}
Unfortunately this doesn't work as expected - the thread
runs only once. I'm sorry that I don't have a handy test
case to show, but could anyone please answer a general
question for me:
Can you instantiate a Thread object and then start()
and halt it (by returning from run()) several times?
Thanks
Alex
public void resize(int w, int h) {
if (thread.isAlive()) {
thread.running = false;
try {
thread.join();
} catch (Exception ex) {
ex.printStackTrace();
}
}
// draw the tiles here (that is quick)
super.setSize(w, h);
thread = new RenderThread();
thread.start();
}
This will always wait for the existing threa to stop then start a new one..
Steve
"A. Farber" <Alexande...@t-online.de> wrote in message
news:c9ccaf83.04072...@posting.google.com...