R
roy.sebastien
Hello All,
I have a class SpecificTask defined as follow:
public final class SpecificTask extends AbstractTask implements
Runnable {
public void initialize() throws Exception {
super.initialize();
...
}
public void execute() {
System.out.println(isShutdownSignalReceived());
Thread thread = new Thread(this, this.getClass().getName());
try {
thread.start();
} catch (IllegalStateException ise) {
logger.error("Couldn't start Recommendation Task thread");
}
}
public synchronized void run() {
while (!isShutdownSignalReceived()){
doSomething();
}
}
}
and of course another class AbstractTask
public abstract class AbstractTask {
private ServiceManager serviceManager = null;
public void initialize() {
shutdownSignalListener = (ShutdownSignalListener)
serviceManager.lookup(
ShutdownSignalListener.ROLE);
}
protected boolean isShutdownSignalReceived() {
return shutdownSignalListener.isShutdownSignalReceived();
}
...
}
if I call the method isShutdownSignalReceived in the execute method of
the class SpecificTask, everything is fine. Though, as soon as I call
it from the run() method, I get a nullpointerassignment. If I debug
it, as soon as I get in the method isShutdownSignalReceived() from the
AbstractTask class, I clearly see that the field is null. I have done
this in the past, what am I doing wrong this time?
I have a class SpecificTask defined as follow:
public final class SpecificTask extends AbstractTask implements
Runnable {
public void initialize() throws Exception {
super.initialize();
...
}
public void execute() {
System.out.println(isShutdownSignalReceived());
Thread thread = new Thread(this, this.getClass().getName());
try {
thread.start();
} catch (IllegalStateException ise) {
logger.error("Couldn't start Recommendation Task thread");
}
}
public synchronized void run() {
while (!isShutdownSignalReceived()){
doSomething();
}
}
}
and of course another class AbstractTask
public abstract class AbstractTask {
private ServiceManager serviceManager = null;
public void initialize() {
shutdownSignalListener = (ShutdownSignalListener)
serviceManager.lookup(
ShutdownSignalListener.ROLE);
}
protected boolean isShutdownSignalReceived() {
return shutdownSignalListener.isShutdownSignalReceived();
}
...
}
if I call the method isShutdownSignalReceived in the execute method of
the class SpecificTask, everything is fine. Though, as soon as I call
it from the run() method, I get a nullpointerassignment. If I debug
it, as soon as I get in the method isShutdownSignalReceived() from the
AbstractTask class, I clearly see that the field is null. I have done
this in the past, what am I doing wrong this time?