How to kill thread

I am facing the problem in killing the thread after some interval. If anybody knows how to kill the thread in middle plz give me reply
Thanks
Sreedhar

Thread.interrupt()
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thre
ad.html#interrupt() is not about killing or stopping
a thread. It is more about kicking a blocked thread.
There is no way to kill a thread. As been said
above, the thread should be designed to accept
instruction to stop gracefully.
The interrupt() was created by sun as a solution sun came up for the problems of thread stop(), it should be the cannonical way to stop a thread.
The problem with having your own mechanism of interrupting a thread is that you should have a method to interrupt a thread execution and a flag that should be checked from inside your thread or runnable code to see if it should stop and if so, do it cleanly. The problem with this aproach is that if the thread is sleeping or in some blocked state, calling your own interruption framework is inefective, as it could never get a chance to run the code.
To solve that, sun privides us with the method( interrupt() ) and the flag ( Thread.interrupted() ) with the advantage that on calling it, it guarantees you that it would take effect even if the thread is in a blocked state.
So, you are right about having to implement your own gracious interruption but the right way to do that is by checking interrupted(). And no Thread.interrupt() is not just about blocked threads, although it covers that ground.
May the code be with you.

Similar Messages

  • How to kill threads in obiee server

    Can some one please tell me how to kill threads in OBIEE server

    944632 wrote:
    Thanks for the prompt reply. your answer is helpful. Here is my problem.
    I am an OBIEE admin and getting lot of complaints fronm developers that BI Server services are not stopping. I was adviced by my senior that i have to kill thresads in the server.
    I followed what you told but when i open the RPD, i am unble to open cache in either offline or online modeHi,
    - Unable to open cache due to you already disabled cache (usage tracking - nqsconfig.ini file) cache diabled that why you can't able to open cache
    just make sure
    [CACHE]
    ENABLE = YES;
    C:\Oracle\Middleware\instances\instance1\config\OracleBIServerComponent\coreapplication_obis1 (obiee11g file path ref)
    - unable to stop biservices? if that case you can kill it different ways, (stop bi services/ctrl +c on services/task manager/FMW (console/EM)/ services.msc etc) which way did you tried?
    (which version did u tired)
    Thanks
    Deva

  • How to kill parent and child thread in sequnece

    Hello freinds,
    I have one class FirstClass which creates one thread Pserver and Pserver creates three threads then how to kill parent Pserver and child threads.........

    define a method that requests that the parent thread terminate itself, and within the code called when the thread is shutting itself down, have it do something similar to its child threads: call methods that request they shutdown themselves.
    One common way to do this is to interrupt the thread.

  • How to kill a Thread?

    Hello,
    My question is simple how to kill a thread.
    The background is a call to a method in a third party API, crawler4j, that locks the entire program.
    The design of crawler4j is "You should stop it when you think it's enough (ctrl+c)" but as I use it only as a step in a larger program I want to stop it programmatically and not by "ctrl+c" as they have designed the API.
    This is the locking callcontroller.start(MyCrawler.class, numberOfCrawlers);So I made a thread public class MyCrawlController extends Thread {
    public void run(){
      controller.start(MyCrawler.class, numberOfCrawlers);
    }And in my main method
    MyCrawlController mCC = new MyCrawlController();
    mCC.start();
    Thread.sleep(180000);
    //Here I want to kill the mCC and all it's threadsOne problem is that my program never terminates. Probably due too the JVM not realizing that I don't want it to count mCC and it's spawned threads as alive. Any idea on how to solve this. For now I can only exit the program with System.exit(0); and I don't want that. So I need a way to stop the mCC's threads and get the JVM not to count them. Any idea on how to solve this. Even better if they can be taken by the GC.

    Farmor wrote:
    Thanks for the answer.
    I came to think about daemons and solved the problem with mCC.setDaemon(true);Really stupid that one has to do several programs and tie them together only to kill a thread.
    As I only do this for other learning purposes and won't use this code or program after this week I will modify crawler4j, open source, and make myself a custom good method that will terminate itself and return to the main method properly.There are some fairly difficult problems with a number of aspects of concurrency if you forcibly stop threads, which is why Thread.stop() and related methods have long been deprecated.
    It's a pity that Java can't respond to kill signals (like Ctrl-C) in a tidy way. I think they're all tied up with some of the JVMs internal processes.
    In general people wind up using sockets instead of signals.

  • How to Kill a Stored Procedure?

    Sombody knows how to kill a stored procedure from another stored peocedure?
    I wanna know if exists a way to use therads in sored procedures.
    Best Regards

    1) You can't. Unless you code a mechanism yourself, but then since
    you can't thread Procedure calls that wouldn't help much.
    2) You can try using DBMS_JOB, if your not in a hurry to have your procedure finish.
    This is PL/SQL, not Java. You have to imagine all you get is a single thread running
    static methods. You can get away from everything being static by using the CREATE TYPE
    OBJECT stuff. but that doesn't help you thread your processes.
    I hope someone else can give you a different answer,
    Eric Kamradt

  • Need some help killing threads (not in the way already mentioned..)

    I have read the ways in which we should safely kill a thread - and for the most part i understand that. But my question is HOW to implement it in the way that I need.
    Basically I have a multithreaded (ewww) app that really is a large job scheduler running 24/7. It can run anywhere from 1 to 15 jobs at a given time. This is fine. What i need is to have the ability to 'kill' a job when I need to. When the app daemon decides its time to run a certain job (based on business logic) it kicks one off, which is a class I made that implements Runnable.
    public class SchedulerProcessThread extends SOQBase implements Runnable{}
    when its time to start a job i do the usual:
    SchedulerProcessThread spt = new SchedulerProcessThread(blah);
    Thread t = new Thread(spt, "fooname");
    t.start();
    Now, this comes to my problem of where/how to kill the job (if needed). A SchedulerProcessThread is linear and finite so it will always have a termination point - it never loops. And when one is kicked off - i do not have a reference to it anymore - I mean, I couldnt if i am constantly running new jobs, potentially hundreds every hour. And jobs can be started in various places in the app, depending upon whether others are already running, etc.
    I wish to implement the do-while (alive) logic on the job thread. So in the 'run()' method of my SPT class, I would like the:
    while (alive) {
    doProcessing();
    But how can i invoke a method on my class [SPT] so that it changes the alive var from true to false when i do not have a reference to it?
    As a side note, I have a command prompt on the app whereby i can call up all the running 'jobs' which is a list of the running threads under a threadgroup called 'soqjob' (all new Threads that are started with a passing param of and SPT object are under the 'soqjob' threadgroup). So now i can see all those 'soqjob' threads which are currently running Thread objects that have been passed new instances of an SPT class.
    Is there anyway i can grab the 'soqjob' thread of my choice and somehow access my SPT class that was originally passed to it in the Thread constructor? if so, then I could pass in the command to stop the do-while loop.
    Hmm - does any of this make sense? If i can sum up, the problem is i do not know how to access my own SPT class once I have passed it into a thread object and invoked that thread object's 'start()' method. if i can do that, then i can switch the ALIVE var from true to false and thereby kill the SPT job i need.
    Any ideas?
    Many thanks
    Ian

    I would add a Collection (synchronized) to the Scheduler that holds a reference to all the Processes. Pass a reference of the Scheduler to the Processes so that when a Process is done, it can remove itself from the Collection.
    public class Scheduler {
         private Collection threads;
         public void addProcess() {
              Runnable runnable = new ProcessThread(this);
              Thread thread = new Thread(runnable);
              thread.start();
              threads.add(thread);
         public void removeProcess(ProcessThread thread) {
              threads.remove(thread);
         private Thread getSelectedThread(Component c) {
              //Find Thread in Collection and return it
         private class Action implements ActionListener {
              public void actionPerformed(ActionEvent e) {
                   Thread thread = getSelectedThread(e.getSource());
                   thread.interrupt();
    class ProcessThread extends ... implements Runnable {
         private Scheduler scheduler;
         public ProcessThread(Scheduler s) {
              this.scheduler = s;
         public void run() {
              while (!Thread.interrupted()) {
                   try {
                        doProcessing();
                        Thread.yield();     //Give the other Threads a chance to do some work
                   } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
              this.scheduler.removeProcess(this);     //Remove this Thread from the Scheduler's Collection
    }Did you consider using the classes java.util.Timer and java.util.TimerTask?

  • JPDA Examples TTY kill thread.

    Hi all:
    I've try to run the example com.sun.tools.example.debug.tty.TTY it works pretty well but I dont understand exactly how to use the command kill:
    kill <thread> <expr> -- kill a thread with the given exception object
    <expr>: a Java(tm) Programming Language expression.
    I dont understand exactly what they mean with the <expr> I've try kill 5 new java.lang.String("Killed") or kill 5 new java.lang.Throwable("Killed")
    Did someone here knows how to use JPDA to kill a thread?
    Can you give me an syntax example for that command?
    Thanks for any help.

    I've found a similar post at
    http://forum.java.sun.com/thread.jsp?forum=47&thread=274201
    timbell tells to use the following syntax:
    kill 0x129 new java.lang.Exception()
    but in my case I've try
    Reference Handler[1] suspend 29
    Reference Handler[1] kill 29 new java.lang.Exception()
    killing thread: 142.120.93.217_170_Receive
    Reference Handler[1] Thread not suspended
    Expression must evaluate to an object
    And it does'nt seems to work.
    Any helps will be appreciate.
    Thanks

  • How to kill Active Data Request in DSO

    Hi all,
    I have 2 dsos ( A, B). Data loads from A to B.
    Now I have deleted data from DSO B by using option delete data ( did killed one running request by turing the status to RED).
    when I try to load data again to DSO B, it is not allowing me to execute the DTP.
    Message is Request 257.617 is stil processing.
    I am SAP BI 7.0 environment.
    Please suggest how to kill active request ( I am not seeing it RSMO/SM37).
    I tried to use Zombie Request FM, it didnt worked.
    Thanks All,
    Jason

    Srinivas,
    Thanks for the reply.
    When I go RSRQ
    I can see the request , the exception it is showing is CX_RS_FAILED logged.
    SM51, when try to kill the process it says
    SAP System Message:
    Work Process restarted; session terminated
    Apologies for earlier post messages saying that I did nt saw the message in RSMO, I can see it is in yellow process.
    Please suggest how to kill the processes .
    Apperciate your response..
    Thank you
    Jason

  • How to kill a job in SM37

    hi All,
             can someone wxplain me how to kill a job in SM37 which is delaed by 10,000 secs.
    cheers

    Hi Rase,
    goto SM37 and click on the active selection and enter the jobname and then click excute the particulr job should appear highlight the jobname then click on the stop iconthat appears on the taskbar( 3 rd from left)
    or goto SM50 Click on the process and select process->stop without core
    or
    set a running infopack of the chain (in RSMO) to red, thats will stop the chain (if there are no parallels, else set all parallels to red).
    ****Assign Points If Helpful****
    Regards,
    Ravikanth

  • Cant sync my iphone contacts with yahoo, it says "unknown error (4)" and tells me to come back later, been doing it for months. Any ideas on how to kill it?

    cant sync my iphone contacts with yahoo, it says "unknown error (4)" and tells me to come back later, been doing it for months. Any ideas on how to kill it?

    Hey joshuafromisr,
    If you resintall iTunes, it should fix the issue. The following document will go over how to remove iTunes fully and then reinstall. Depending on what version of Windows you're running you'll either follow the directions here:
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    http://support.apple.com/kb/HT1925
    or here:
    Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7
    http://support.apple.com/kb/HT1923
    Best,
    David

  • URGENT: How to run threads in sequence?

    Dear experts, I am new to writing threads. I would like to know how to run threads in sequence? How do I know when a thread finishes its task?
    In the following code, classes Process_A(), Process_B(), Process_C() and Process_D() are subclasses of Class Thread.
    I'd like to know if I am using the join() function correctly? My intention is to wait for the previous process to finish before running the current process.
    Could anyone kindly give me some solutions on how to run the processes in sequence?
    Thanks!!
    =============================================================
    Thread process;
    Vector process_names = new Vector();
    process_names.add("a");
    process_names.add("b");
    process_names.add("c");
    for(int i=0; i<process_names.size(); i++)
    String process_name = (String) process_names.elementAt(i);
    if(process_name.equals("a"))
    process = new Process_A();
    else if(process_name.equals("b"))
    process = new Process_B();
    else if(process_name.equals("c"))
    process = new Process_C();
    else if(process_name.equals("d"))
    process = new Process_D();
    timer = new javax.swing.Timer(1000, new ProcessListener());
    timer.start();
    // ProcessListener()
    class ProcessListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    if(process!=null)
    if(process.isAlive())
    try
    process.join();
    catch(Exception ex)
    ex.printStackTrace();
    process.start();

    just look at this simple example u will get to know how to use join method
    This does exactly what u want
    class callme
    void call(String msg)
    System.out.println("["+msg);
    Try
    Thread.sleep(1000);
    catch(InterruptedException e)
    System.out.println("interrupted");
    System.out.println("]");
    class caller implements Runnable
    String msg;
    Callme target;
    Thread t;
    Public Caller(Callme targ, String s)
    target=targ;
    msg=s;
    t=new Thread(this);
    t.start();
    public void run()
    target.call9msg);
    class Synch
    public static void main(String arg[])
    Callme target=new Callme();
    Caller ob1=new Caller(target,"hello");
    Caller ob2=new Caller(target,"Synchronized");
    Caller ob3=new Caller(target,"world");
    Try
    ob1.t.join();
    ob2.t.join();
    ob3.t.join();
    catch(InterruptedException e)
    System.out.println("interrupted");
    waiting for dukes

  • How to kill TP process at OS Level

    Dear ALL,
    How to kill the TP process at OS level
    Operating System : win 2003

    Q.1 Different Method for Kernel Upgradation
    So far till now, I have known only one method for Kernel upgradation which is very very simple. I dont think we need any other work-around for Kernel upgrade as this method is very very straight forward. The steps to be followed are ---
    Go to the SAP OSS Site :- 
    http://service.sap.com/SWCenter-Main
    From here Download the kernel programs in a temporary folder or use Download Basket toi download the Kernel.
    Now shutdown the R/3 database and all services including saposcol. 
    Create a folder and copy the original executables from  /exe/run/ directory then uncar the downloaded files and replace the original executables in /exe/run/ directory. 
    Then restart your system. 
    A couple of important points to remember are :-.
    a) Always make a copy of the files you're going to replace. For e.g. Create a directory (oldkern) and copy all the old files before replacing them (this helps when sometimes the new Kernel has problems, and you can revert it)
    b) You have to shutdown SAP and the Database using the OLD kernel file. Again it is good practice to shutdown everything first.
    Regards,
    Mandar

  • How to kill process/Actavity in SAP ?

    How to kill process/Actavity in SAP ?

    The core file contains the memory state of the work process at the point it was terminated. You could use it for debugging the work process if you had access to the kernel source code, which you don't unless you are SAP. For most people, then, the core file is of no interest and just takes up space in the operating system's file system. Using "cancel without core" is the thing to do.
    That said, sometimes I find "cancel without core" doesn't actually work but "cancel with core" does. I always try without core first, but occasionally have to resort to with core. If you do cancel with core, make sure to go and delete the core file afterwards to avoid the file system filling up. Work process core files can be large. You'll find it in a directory/folder here - /usr/sap/SID/DVEBMGS00/work (substitute DVEBMGS00 as appropriate).
    Steve.

  • How to kill a  session in stored procedure or trigger.

    Can anyone let me know, how to kill a particular session in stored procedure or trigger.
    Regards
    KVSS

    also you cannot attempt to kill ur own current session.
    But on what circumstances you want to kill the session.
    When anyone trys to access a table and lets suppose the trigger onthat table activates
    and you want to kill that very session which activated the trigger ???
    i dont think its possible. To kill a session definitely you should be in a different session and
    then only you can achieve that.
    pls check it out
    prakash
    [email protected]

  • How to kill a workflow in runtime?

    Friends plz let me know how to kill a workflow in runtime?.

    Hi,
    You can use SAP_WAPI_SET_WORKITEM_STATUS to logically delete the work Items. Just pass the status as "CANCELLED" to this function module.
    Logically delete means workitem will be deleted from the table but with archiving.
    Report RSWWWIDE (txn SWWL) deletes work items from tables without archiving, I mean work item will be deleted permanently.Therefore, this report should not be used in a production system.
    Thanks
    Yogesh Sharma

Maybe you are looking for