Hi all,
I'm having some problems with a thread that I just can't interrupt.
I'm using sleep in this method and when the sleep is interrupted I catch the InterruptedException that is thrown but the thread just runs on and is not interrupted.
Has anyone an idea why the thread is not interrupted?
Here's the code I used:
With the firePositiveEdge(InputLink) method it is started (which works quite well).
When the method fireNegativeEdge(InputLink) is executed the thread should be interrupted but it isn't. It just runs on and activates or disactivates the object till I end the execution of my simulation.
If anyone has an idea what I'm doing wrong that would be gread. Thanks guys.
private int activationTime;
private int disactivationTime;
private Thread pulseGeneratingThread;
public PulseGenerator() {
this(1000, 1000);
}
public PulseGenerator(int activationTime, int disactivateionTime) {
this.activationTime = activationTime;
this.disactivationTime = disactivationTime;
for (int i = 0; i < inputLinks; i++) {
inputLink.add(new InputLink(this));
}
pulseGeneratingThread = new Thread(new PulseGeneratorThread(), "PulseGeneratorThread");
outputLink = new OutputLink(this);
setImage(createImage());
}
class PulseGeneratorThread implements Runnable {
public void run() {
while(true) {
setActivated(true);
try {
Thread.currentThread().sleep(activationTime);
}
catch (InterruptedException ie) {
//ie.printStackTrace();
}
setActivated(false);
try {
Thread.currentThread().sleep(activationTime);
}
catch (InterruptedException ie) {
//ie.printStackTrace();
}
}
}
}
protected void firePositiveEdge(InputLink link) {
pulseGeneratingThread.start();
}
protected void fireNegativeEdge(InputLink link) {
pulseGeneratingThread.interrupt();
setActivated(false);
}


