Re: XMPP Java bot loop question [follow-up]
Well, I have changed a few things, and it's seemingly working Ok. Any
and all tips are welcome, since I'm just going trial-and-error.
First of all, implement Runnable and have an extra thread instance:
public class BotMain implements Runnable {
private static Thread mainloop = null;
// ...
public static void main(String[] args) throws Throwable {
BotMain bot = new BotMain();
// ...
try {
addShutDownHook();
// connect DB and XMPP
// ...
} catch (final Throwable e) {
logger.fatal("Startup failed", e); // <- this doesn't log to
logfile now
shutdown();
System.exit(1);
return;
}
mainloop = new Thread(bot);
if (mainloop != null) {
mainloop.start();
}
}
protected static void addShutdownHook() {
Runtime.getRuntime().addShutdownHook( new Thread() {
public void run() { BotMain.shutdown(); }});
}
// ...
public void run() {
while (!isShutdownRequested()) { // set in shutdown(), which is
called from the shutdown hook
Thread.currentThread().yield();
}
}
The logging problem is one that sticks out right now.
I have tried wrapping the log call in an invokeLater(), but no effect -
the exception shows up in Netbeans but not in the logfile.
--
Sabine Dinis Blochberger
Op3racional
www.op3racional.eu