Skip to Main Content

Killing a thread ( runnable ) - problem

938644Oct 10 2012 — edited Oct 13 2012
Hi,
I already posted about this, and got a good answer.
But, I still have a probalem :
Here is a piece of my code :
// this is the bean which is in the EPN and I want it to create a thread that prints something :


public class EventListener implements StreamSink,com.bea.wlevs.ede.api.DisposableBean ,InitializingBean {
......
// the relevant methods:

RunnableTestBean runnableTestBean; // this is the thread which suppose to print ..

public void destroy() throws Exception {



System.out.println("destroydestroydestroydestroydestroydestroydestroy");
runnableTestBean.suspend();

}

public void afterPropertiesSet() throws Exception {
runnableTestBean=new RunnableTestBean();
runnableTestBean.run();
//System.out.println("afterPropertiesSetafterPropertiesSetafterPropertiesSet");

}

...

and the class RunnableTestBean :

public class RunnableTestBean implements RunnableBean {


boolean stopped=false;
public void run() {
while ( !stopped){
System.out.println(" printing...");
try {
wait(5000);
//Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println(" Stoping thread ??");
e.printStackTrace();
}
}

}

public void suspend() throws Exception {
stopped=true;

}

....

The thing is that when I use the method as above :

..
public void run() {
while ( !stopped){
System.out.println(" printing...");
try {
wait(5000);
//Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println(" Stoping thread ??");
e.printStackTrace();
}

When I undeploy the application , the destoy method ( in EventListener class ) is not called !
but,
if I implement the run "run" method like this :

public void run() {
..
System.out.println(" Something ");

}
than everything is fine!

The differrence as you can see , is that when I use an infinite loop - the destroy method never called ( seems that the caller waits for it to stop , and that's why the
destroy method not called )

When i don't use the infinaie loop- it's OK.

So, any help ?
Thanks ..
Comments
Post Details
Added on Oct 10 2012
5 comments
743 views