Stop an OSGi thread

Hi everyone!
I am programming a OSGi bundle using Eclipse. The problem is that I don't know how to use the stop method in the Activator class so my program does never stop and I have to stop it by hand. For example:
public void start(BundleContext context) throws Exception {
      System.out.println("Starting bundle"); }
public void stop(BundleContext context) throws Exception {
     }The console shows the Starting bundle message but instead of stopping the program after doing the only thing it must do, it does not stop. What should I write in the stop thread so that the program after showing the message stops?
Thanks in advance!

What exactly are you trying to do? Calling Thread.stop( ) is inherently a bad idea (see the Javadocs).
You are getting a IllegalStateException because Thread.stop( ) kills the thread, you would need to create a new thread to resume execution.
If what you are trying to do is pause execution, you probably want to redesign your thread's tasks into smaller chunks that can be launched separately. Alternatively, have the thread check it's interrupted state and if a flag was set block on a monitor until you want it to resume execution.

Similar Messages

  • Cannot stop memory monitor thread

    Hi All,
    I am getting the following error intermittently in a dataflow which has degree of parallelism = 8.
    22943 0 SYS-170111 27/11/2009 12:22:05 |SubDataflow DF_Conform_ISI_Person_Match_Prep_1_9
    22943 0 SYS-170111 27/11/2009 12:22:05 Cannot stop memory monitor thread: <RWThreadImp::terminate - No thread is active within the runnable>
    Any ideas as to the cause ?
    Thanks,
    Eric Jones.

    We are having the same issue.
    According to ADAPT00890818, this issue should be resolved in 12.0.0. We are currently running with version 12.2.2.3.
    Please advice.

  • I have several times tried to stop following a thread in the PDF's forum about security issues and i still keep getting flooded with emails from this thread. I used the action within the thread that says stop following but appears to have no effect I stil

    I have several times tried to stop following a thread in the PDF's forum about security issues and i still keep getting flooded with  emails from this thread. I used the action within the thread that says stop following but appears to have no effect I still keep  getting from 5 to 20 emails daily. Please help!!!!!!!

    This may be helpful: How do I disable email notifications?

  • SYS-170111 - Cannot stop memory monitor thread: RWThreadImp::terminate -

    Hi Experts,
                  WE have this warning in pretty much every job in production. But the warnings are not specific to certain jobs they might occur one day and not the other day.
    Cannot stop memory monitor thread: <RWThreadImp::terminate - No thread is active within the runnable>.
    I know looking at the release notes this issue was fixed in 3.0 (12.0.0), we are using 3.2 (12.2.0) and having the same issues. The job server is on a linux 64 bit. I have not seen this issue in any of our windows job server. Is this bug specific to linux or is there a resolution for this.
    Appreciate your help in advance.
    Thanks
    AJ
    Edited by: alangilbi on Sep 28, 2011 5:17 PM

    Hi, AJ.
    As can be seen in the KBA 1455412 this is a known behavior.
    "As a result of fixing the problem identified in ADAPT 00890818 in release 12.0.0.0, this message is displayed by design. If there is really a problem in stopping the memory monitor thread an exception is thrown and an error message is logged.
    Background:
    In the memory monitor's shutdown logic, once it tells the monitor thread to shutdown it waits for the thread to terminate but only for 10 seconds. It could be that at this same time the wait expired when the thread actually terminates. So when this happens in the shutdown logic we force terminate the thread. Since there is no active thread anymore the terminate call throws an exception and then we catch it and then throws the error for the job."
    You can just ignore this warning.
    Leo.

  • How do I STOP & DESTROY a thread?????

    I cannot seem to get my wait cursor to work. Sometimes it appears, sometimes it doesn't. After searching the forums I saw that I must put my long computational code in a seperate thread to get my wait cursor to be painted...
    My question is: How do you stop & destroy a thread? Or will it automatically stop/destroy itself when done running?

    Currently, what I am doing is:
    //set cursor
    public void run() {
    //long process
    //set cursor to normal
    This seems to work fine, but I just wanted to make sure there is not stop/destory method. I didn't want 50 empty thread floating around. I am new to using threads...
    Thanks!

  • Stop the running Thread

    Hi
    i am calling the thread .in the midlle of running thread i have to stop the thread .please help me .
    my senario like . I am calling the scripts . i am wating certain period to complete the script exection . if the scripts are not available its still wating for a long time . so i am using the thread to execute the scripts and (main thread )checking each duration is completed or not . if the duration completed i am stoping the thread with Thread.Stop() method . but the thread still is alive . next time when i call Thread.Start() its throwing "java.lang.IllegalThreadStateException".
    please help me this .
    Thanks in advance
    public class TestCaseScriptProcessor extends Thread {
    public String execute(){
    TestCaseScriptProcessor caseScriptProcessor = new TestCaseScriptProcessor();
    caseScriptProcessor .start();// second time throwing java.lang.IllegalThreadStateException.
    while (!isExpired) {
    caseScriptProcessor.stop();
    public void run() {
    Edited by: 849614 on Jan 17, 2013 6:17 AM
    Edited by: 849614 on Jan 17, 2013 6:22 AM

    What exactly are you trying to do? Calling Thread.stop( ) is inherently a bad idea (see the Javadocs).
    You are getting a IllegalStateException because Thread.stop( ) kills the thread, you would need to create a new thread to resume execution.
    If what you are trying to do is pause execution, you probably want to redesign your thread's tasks into smaller chunks that can be launched separately. Alternatively, have the thread check it's interrupted state and if a flag was set block on a monitor until you want it to resume execution.

  • Stopping a simple Thread

    I read the article http://download.oracle.com/javase/6/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html but it did not helped me much.
    Here is a simple scenario that I'm unable to solve.
    Consider a misbehaving thread:
    public class Nano extends Thread {
         @Override
         public void run() {
              while(true) {
                   System.out.println(System.nanoTime());
    Assume that the class above is a third party tool and I cannot modify it. (Eg. I cannot add a flag to the loop like - while(keepRunning))
    I create a class to run this misbehaving thread, and try to KILL it after a certain timeout:
    public class MyThreadDemo {
         public static void main(String[] args) {
              Thread t = new Nano();
              System.out.println("Starting the new thread");
              t.start();
              // Some operation
              t.interrupt();
              System.out.println("Thread is now Stopped. Terminating Application.");
    Well, the message "Terminating Application" is printed, but the thread Nano keeps running for ever.
    Can you suggest a possible solution, a safe way to stop the thread?

    837595 wrote:
    I read the article http://download.oracle.com/javase/6/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html but it did not helped me much.
    Here is a simple scenario that I'm unable to solve.
    Consider a misbehaving thread:
    public class Nano extends Thread {
         @Override
         public void run() {
              while(true) {
                   System.out.println(System.nanoTime());
    }Assume that the class above is a third party tool and I cannot modify it. (Eg. I cannot add a flag to the loop like - while(keepRunning))
    I create a class to run this misbehaving thread, and try to KILL it after a certain timeout:
    public class MyThreadDemo {
         public static void main(String[] args) {
              Thread t = new Nano();
              System.out.println("Starting the new thread");
              t.start();
              // Some operation
              t.interrupt();
              System.out.println("Thread is now Stopped. Terminating Application.");
    }Well, the message "Terminating Application" is printed, but the thread Nano keeps running for ever.
    Can you suggest a possible solution, a safe way to stop the thread?Run it in a separate JVM.
    You want two threads in the new JVM.
    One control thread that interacts with your original app in the original JVM.
    One daemon thread that runs the misbehaving code.
    When your original app in your original JVM tells the control thread in the new JVM to exit
    there will only be a daemon thread left and the JVM will exit.

  • Stopping a blocked Thread

    I need to stop a Thread, or interrupt a blocked I/O.
    I'm making a call to a library that I do not own and cannot change. The library makes a HTTP connection to a service and waits for a response. As far as I know, the library uses BufferedReader to read the service response. If the service is down, then no response is ever returned, and the BufferedReader read simply blocks.
    I cannot change the library to be intelligent, of course, and don't have very good luck getting the service support to fix their stuff. But I have to use the library. How can I interrupt the blocked I/O read?
    What I've tried is as follows, but I'm not convinced it's the right way. My application is a long-running application that does not exit very often, so I'm concerned also about gc not properly recycling the resources due to still having the blocked thread still there (and this has impacted subsequent executions, even though I use local variables where I can).
            // Create a new Thread to wait on the submission
            Thread t = new Thread() {
                public void run() {
                    response = event.submit();
            t.setDaemon(true);
            t.start();
            try {
                t.join(timeOut);
                msg = "Attempt to connect to ESM Server timed out";
            catch (InterruptedException e) {
                msg = e.getMessage();
            }The other option I was thinking of, was coding my call to ESM server in a separate Class with a main, and invoking it via Runtime.exec. That way, at least I'm 100% sure that the code exits, and I can use System.out/err to receive the "output".
    Given that Thread.stop() is deprecated, and that you theoretically cannot interrupt blocked I/O, how have others solved this problem?
    Thanks,
    Matt

    ...you theoretically cannot interrupt blocked I/O, how have others solved this problem?I've done it your way. Each thread does an access. If it takes too long, then it may never respond and I ignore it. I also log the error condition and try to notify and administrator.
    Threads probably take up about a megabyte of memory so I may run out of memory it the problem doesn't get fixed by manual intervention.
    Your idea of using Runtime means that you create a new JVM for each ESM. If a thread takes up a megabyte, the new JVM takes up many, many megabytes. Instead of running out of memory in the JVM, you may run out of memory in the Box.
    Every situation is different. My thread approach works for my application. What works best for you is your call.

  • Stopping  a child thread

    Here is a class that will create a process thread. The process thread will talk to a database through another class.The process thread should return the result within *30* seconds.If it returns before *30* second it is fine. Help me how to stop the process if it takes more than 30 second.
    public class Details{
    //Method will return a Map
    public Map getDetail(String name){
    ProcessThread process = new ProcessThread (); //This is new thread
    process.setName(name);
    Thread t = new Thread(process);
    long initTime = 0;
    long startTime = System.currentTimeMillis();
    long sleepTime = 30000;
    t.start();
    try{
    //the process thread should return a Map with in 30 seconds.The current thread sleep for 0ne second and checks the time is exceeding *30* seconds and the process thread is still running.If the process thread returns before *30* second it is fine otherwise it shoild kill the process thread
    while (t.isAlive() && initTime < sleepTime) {
    initTime = System.currentTimeMillis() - startTime;     
    Thread.sleep(1000);
    if (elapsedTime >= sleepTime) {
    throw new Exception();
    }catch(Exception e){
    return process.getDetailsMap();
    Here a code for a process thread
    public class ProcessThread implements Runnable {
    private String name;
    private Map detailMap;
    public void run() {
    detailMap = //here code for calling a class that will connect to database and process the result and return a "Map" .This will return within 30 second.If not i have to stop this thread.
    setDetailsMap(detailMap);
    pubilc void setName(String Name){
    this.name = name;
    public Map getDetailsMap(){
    return detailMap;
    Edited by: ragavarnan_call_screen on May 27, 2008 11:46 PM

    First create a timer thread that fires after the time period and which can be cancelled.
    If it fires (hasn't been cancelled) then one of the following must occur.
    1. If and only if the driver/database is fixed and the driver supports the Statement.cancel() method then use it. You must test this and be sure to test for regular queries and procs as well.
    2. Close the connection.

  • Stopping and Restarting Threads

    Please help!!!! I have a situation similar to the classic producer consumer but I need to be able to stop the producer and consumer for some time so I can change some parameters (for example increase the buffer size) and then restart them with the new parameters. Is this possible? If it is how would I go about it.
    Thanks

    just "kill" the thread by setting it's stop condition to true and then start a new one.
    i.e.
    public someClass extends Runnable{
    private boolean keepRunning = true;
    public void killMe(){
         keepRunning = false;
    public void run(){
         while(keepRunning){
                \\do some interesting things !!!
    }

  • Labview stopped executing mutli-threaded

    Hi I have a serious problem.
    I have created a windows keyboard hook DLL and I call this DLL from Labview. Now in labview there are 2 threads (2 completely separated while loops) one for ControlPanel and one for processing data.
    Now DLL works with events, so one of the DLL calls freezes the processing thread until there is data available.
    Now the ControlPanel thread does what it does and it doesn't care if the other thread is frozen.
    So until today everything worked perfectly. Now I'm not sure but it looks that since I've build an application (exe) the vi runs as single threaded VI. Now this means that as soon as the processing 'thread' is stopped the whole application really stops.
    Now does somebody knows how to force Labview to use multiple threads? As I don't want to write the whole VI again. And more I would really like to know this.
    Peace
    Waldemar
    Attachments:
    example.zip ‏112 KB

    Found the answer -> in Call Library Function window the function must be set to reentrant so that the Labview knows the function can be run in any thread.
    Peace
    Waldemar

  • (J2ME) Stopping a blocked thread

    In J2ME, receiving a datagram blocks the current thread until a datagram is received. I have created a thread that simply receives a datagram and then loops waiting for the next one. How do I stop the thread when it is blocking in datagram receive waiting for a datagram to come in? I am using the code on http://java.sun.com/j2se/1.3/docs/guide/misc/threadPrimitiveDeprecation.html for a reference, and it mentions calling Thread.interrupt() but this method does not exist in J2ME.

    I tried searching for any API on J2ME... it looked like there were a lot of different specifications, and in any case I never found any API docs.
    However, i did want to say this:
    In regular java, the way you would normally do this is (ThreadObj).interrupt(), but you said this didn't exist. Are you 100% sure?
    If that's not working, I have 2 other ideas:
    1. Thread.stop() - it has been deprecated and is not technically "safe" but it could probably work in a pinch.
    2. There is often a way to put a timeout on an inputstream. See if you can do that.

  • Stop a running thread

    I create a thread and while it is running i want to stop it but not wait what should i do to solve this problem.
    Edited by: phamthao on May 24, 2009 12:13 PM

    public class Example implements Runnable{
         private boolean isRunning, MISTAKE;
              isRunning = true;
              MISTAKE = false;
              Thread thread = new Thread(this);
              thread.start();
         public void run(){
              while(isRunning){
                   //do stuff
                   if (MISTAKE){
                        isRunning = false;
    }Pretty general

  • Child thread stopping a parent thread

    I have a java program which has to pick some list of records from table1 and iterate through the list and send a message to an external URL and after getting a response update the same table.
    The issue here is I use HttpUrlconnection and open an InputStream from the connection to read the response message from the external URL.
    This Java program hangs when getting the response from the external URL.(for some reason the external server is busy and does not send a response in time)
    I need to find out some way to get this process out, from waiting for the response from the external URL.
    I have used HttpUrlconnection.disconnect and Thread.interrupt ... both do not "get the process out of wait for response".
    Do any of you have a solution to this issue ?
    Thanks.

    sukumar.sudha wrote:
    Java 1.4 doesnot have setConnectTimeout and setReadTimeout.So I prefer using setSoTimeout.I think it would be easier to start a thread that does the HttpURLConnection stuff and
    when done notifies you (Object.notify()). After you start the thread, you wait(timeout).
    When this wait returns, you can check if the other thread is done or not.
    If yes, all fine. If not, you have your continuation without waiting for completion of the
    HttpURLConnection stuff. The HttpURLConnection will still be attempting to extract the data,
    but should you really care? You achieved the goal of having your main thread move forward.
    Why I think this is better? Simply HttpURLConnection gives you lots of free stuff that you
    would have to implement yourself with sockets.

  • Stopping a java thread via PL/SQL

    I started a java thread from a stored procedure and I can't seem to kill it unless I drop the DB. Can anyone tell me if there is a way through PL/SQL to kill the thread I started.
    Also is there a way to start a thread and advance my PL/SQL block? I can't seem to proceed in my block of code.
    Thanks
    Any help!

    Jack,
    I didn't understand pretty much...
    couldn't you explain a little bit
    better how to do it?
    thanks for your attention,
    Dan
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Jack Tsai ([email protected]):
    Dan:
    Please check the following forum message for your question:
    http://technet.oracle.com:89/ubb/Forum88/HTML/001611.html
    Jack<HR></BLOCKQUOTE>
    null

Maybe you are looking for