How to stop the thread?

Hi,
How to stop the thread in java. This is my program.
import java.net.InetAddress;
public class ThreadPing extends Thread {
     ThreadPing(String pingIP)
          super(pingIP);
          start();
     public void run()
          try
          String pingIP = Thread.currentThread().getName();
          InetAddress inet = InetAddress.getByName(pingIP);
          Boolean get=inet.isReachable(1500);          
          if(get==true)
               System.out.println(inet.getHostName());               
          }catch(Exception e)
     public static void main(String args[])
          for(int i=1;i<=100;i++)
               String pingIP = "192.168.1."+i;
               ThreadPing tp = new ThreadPing(pingIP);
Thanks in advance.

The simplest way to stop all the thread is to make all thread daemons and exit the program when you want them to stop.

Similar Messages

  • How to Stop the process of Thread

    Hi,
    A process is running in a thread, which will create a file with records in it.
    I have a cancel button and if I click the button, the process should be stopped i.e. it should not allow to create the file. Is it possible to do this?
    If so, how to achieve this? Please help me in this regard...
    Thanks in Advance

    Hi,
    A process is running in a thread, which will create a
    file with records in it.
    I have a cancel button and if I click the button, the
    process should be stopped i.e. it should not allow to
    create the file. Is it possible to do this?
    If so, how to achieve this? Please help me in this
    regard...
    Thanks in AdvanceThere is no (safe) way of just stopping the thread. What you can do is have a flag in your Runnable/Thread object that you flip when you click the Cancel-button. Then in your run() method you check every now and then if the flag has been flipped. If the flag has been set you stop what you are doing and do necessary cleanup.
    Something along these lines should do it (this is just a skeleton code that won't compile, but the general idea should hopefully be clear):
    class FileCreator implements Runnable {
        private File file;
        private boolean cancelled = false;
        // Method to call when you click the Cancel-button
        public synchronized void cancel() {
            cancelled = true;
        public void run() {
            // Do whatever it is you need to do. On suitable places in the code you check if
            // the job has been cancelled. E.g.:
            try {
                if( cancelled ) {
                    return;
                // Create the file
                file = new File(...);
                if( cancelled ) {
                    return;
                // Add the records to the file:
                for( Record rec : getRecords() ) {
                    if( cancelled ) {
                        return;
                    addRecordToFile(rec, file);
                // etc, etc
            finally {
                // Do necessary cleanup if the job was cancelled, e.g.:
                if( cancelled ) {
                    if( file != null ) {
                        // The file was created before the job was cancelled. Delete it:
                        file.delete();
                    // etc, etc
    // Somewhere else in your code:
    FileCreator fc = new FileCreator();
    new Thread(fc).start();
    JButton btnCancel = new JButton("Cancel");
    btnCancel.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            fc.cancel();
    ...Hope this helps!

  • URG & IMP: How does one stop the Thread.currentThread?

    hi,
    I want to stop the current thread.
    Presently teh code used Thread.currentThread.stop()
    However stop() has been deprecated
    Thread.currentThread.interrupt() doesnot seem to help.
    If I try Thread.currentThread.isAlive() post tehinterrupt, it doesnot work as desired and teh thread is still active...
    Any pointers????
    We have alreday tried using the boolean volatile varible to stop the thread as recommended by sun and since this is the currentThread, it cannot be assigned to null.
    Thanks
    Priya

    hi,
    I want to stop the current thread.
    Presently teh code used Thread.currentThread.stop()Whyever would a thread want to deliver a stop() to itself.
    Did you mean that you wanted to stop() a different thread?
    As indicated in the (depreaction) documentation for stop(), using interrupt()
    is a better idea. However, that requires you to have a protocol
    where the receiver of the interrupt then reacts in an appropriate
    manner, i.e. interrupt() can be the basis for cooperative
    thread termination; it can't merely replace a stop() call
    in an existing application without any other changes.
    >
    However stop() has been deprecated
    Thread.currentThread.interrupt() doesnot seem to
    help.
    If I try Thread.currentThread.isAlive() post
    tehinterrupt, it doesnot work as desired and teh
    thread is still active...
    Any pointers????
    We have alreday tried using the boolean volatile
    varible to stop the thread as recommended by sun and
    since this is the currentThread, it cannot be
    assigned to null.Think about what you are trying to achieve. Did you want
    to just do a Throw() out of the current method, with (or
    without )a corresponding Catch() in some outer context)
    so that the you can unwind in case of an exceptional
    condition and have the thread exit?
    >
    Thanks
    Priya

  • How to stop the running infospoke

    Hi Experts,
    there is a infospoke is still running so long time, it's incorrect, i'll cancel it as kick off the dependenies, i have no idea to how to stop the running infospoke. Anybody could tell me how to do it. thanks in advance.

    hi denny,
       Go to SM37 , find the job , stop the process
    or
       To stop the job find the job with the help of the request name ( TC - SM37 ),then in the job Details find the PID .
    find the process in the process Overview (SM50 / SM51 ).
    Set the restart to NO and Cancel the process without core
    u can also see these threads that are already posted:
    stopping v3 run job LIS-BW-VB_APPLICATION_02_010
    how to cancel or change the background job which is scheduled
      In SM37, for the job , click on Step button. Then from the menu Goto > variant. You can see the process chain name here.
    sure it helps
    Thanks
    Varun CN

  • How to stop the backup process....

    How to stop the backup process....
    Okay, so it happens nearly everytime you synch your iPhone with your iTunes? Easy. As soon as it starts, hit the "X" in the bar where the backup process is being shown, this does NOT STOP the synching process, ONLY the backup process.
    HOWEVER, keep in mind that a few times during the week (depends how often you synch ur iPhone) it will be good to let the backup process let run fully.
    There we go. Problem solved...

    i agree its what i do i backup whenever i add a new app, or take more pics etc its exactly what i do its what ive been saying on all these threads talking about backups etc, im hoping in 2.0.1 will be bug fixes about this sort of thing...

  • How to stop main thread ?

    Hi,
    Inside my java class, after I launch a GUI, I want to stop this main thread. After user make some choice and close GUI window, then, I want to go back to main thread. I use wait() method inside my class to stop main thread , but it does not work and it give me "IllegalMonitorStateException" error. I met same thing, when user close the GUI window and call method notifyAll(). How to stop main thread for a while and how to go back?? Thanks
    Gary

    Hi,
    you can create a boolean, and create a while loop, with a Thread.sleep(time); when you want to continue, you just have to change the state of your boolean. So you don't hava to exit the main. And you can't restart a run() in a thread. You can run it only once, so try to keep in your run() with an appropriate loop.
    Hope it helps.
    S�bastien

  • How to stop a thread in java 1.5 on windows

    Hi All,
    I am using Java 1.5 on windows plateform. I want to stop all the threads which belongs to a particular process when the timeout occurs. In java 1.5 stop() method is depricated and interrupt method just sets the flag and does not stop the thread actually.
    Is there any way to destroy the thread permenently. I am using TheadPool Executor class.
    Regards
    Rinku Garg

    Hi,
    I am having a timer task which is scheduled to run after some fixed time interval when the process started.
    Now this timer task when started, should destroy the active threads of the request. When the request is timed out then the thread is action should termininate.
    In my case run method of particular thread had already made a call to Database through DAO when the time out occurs. So how can I set up a loop in run method which I found on google.
    thread.stop() is deprecated.
    thread.destroy() is deprecated.
    I used thread.interrupt() but it does not stops the thread.
    Please help me in this scenario.
    Regards
    Rinku Garg

  • How to stop a thread forcefully. do reply urgent

    i would like to stop the thread . i have used stop() method and also i have tested by giving the threadname = null. but these two not worked . how to stop thread forcefully. urgent.
    with regards

    There is no direct way to stop the thread forcefully. If you have implemented the thread, modify the code so as to break on some flag.
    i.e.
    public void run()
    while (keepRunning)
    ...do some stuff here
    and provide some way to set the boolean keepRunning as false. The loop will exit and the thread will also be destroyed.

  • How to stop a threads that makes I/O calls ?

    Hi,
    I've a business method that calls a Stored Procedure and makes lots of calculations. This method works inside its own thread, because I do not want to stop the GUI from accepting user actions.
    My problem is : this method may take from 5 minutes to 1 hour to process, depending on the size of the input. Sometimes, for any reason at all, the user may want to stop this execution (pressing a button on the GUI). How can I safely stop the thread ?
    I know I should not use stop() and suspend() because they are deprecated. And I do not use loops (remember it calls only a StoredProcedure that makes all processing), so I cannot use a variable nor interrupt(), because they do not work.
    Do you know any other way to stop this thread's execution ? By the way destroy() is not implemented.
    Thanks and regards.
    Bruno

    Are you saying that the 5 minutes to an hour is all spent in the stored procedure?
    If so the only real solution is to kill the statement - I'm not sure how the DB will handle that, but it will certainly free up your cycles.
    To do that without violating encapsulation, you just need to keep a reference to an object that knows something about the DB connection - you don't have to actually pass around the JDBC objects.
    Consider an object like this:
    public class DoLongProcedure {
       private Statement dbStatement;
       public double doLongCalculation() {
          dbStatement.execute(...);
          // etc
       public void interruptCalculation() {
          dbStatement.close();
    }You create an instance of this object and call its doLongCalculation() method to start everything. You have a reference to this object somewhere, because you are waiting for a response. When the user wants to cancel the process you just call the interruptCalculation() method.
    You have not violated your separation of functionality - if you find a new way to stop the process without killing the statement later, you just reimplement that method.

  • How to stop the "renew cloud subscription"

    I cancelled my Cloud membership a couple of months ago, when I purchased the Master suite. I haven't uninstalled the Cloud downloads yet, which I'm sure is the problem. Do I need to uninstall all of the softwares now and reinstall the purchased one's again, or can I just uninstall the Cloud software and be cool?
    I've also gotten an error message when opening up Illustrator, saying that I need to rt click the .exe file so that it can be repaired, not sure what the heck that means but it's happened everytime I've opened that software since I bought it and it's a little disturbing, do you thing that doing the above will correct that issue?
    Thanks for your help!

    Ken G. Rice wrote:
    Perpetual license customers will get the features in the next version, in this case CS7. So Creative Cloud subscribers are getting an early release of certain features.
    Yeah but I wouldn't be surprised if some new features for cloud users are held back and happen soon after the release and are chalked up to Adobe had to make a cut off for distribution (how it normally goes), so the cloud members feel like they are getting more and the perpetual users are again left to ponder the cloud. Nice carrot on a stick system the cloud presents.
    studysmart50 wrote:
    I just wanted to say that I'm very impressed in the amount of great feedback received via this forum. I will most definitely use this resource for future Q & A.
    ;-) I really wouldn't be too impressed or that surprised, here is why....
    Your thread title - How to stop the "renew cloud subscription" - along with your message stating you cancelled your "Adobe Creative Cloud" membership, well these two things brought out the Adobe Staff as they want everyone they can to get on the Cloud, and no doubt made them cringe at the thought of people canceling the program even though your allowed to as its your choice depending on your terms. Then you have the users who understand the facade of the cloud marketing machine and many prefer to own a perpetual license, we chime in because we are not in agreement with the whole rent your software idea and to pay money to be Adobe's Official Beta Testers via the cloud, which is marketed as cutting edge new features for cloud members.
    Had your thread been something about a feature not working properly since illustrator CS2, or missing since AI8, it would more than likely went unnoticed by Adobe, even if submitted officially via the aptly named "wishform" (Appropriate name as thats what most of it ends up being, hopes and wishes that go unfulfilled or are fulfilled 14 years later like the Package Files feature). New features (regardless of however half backed they are) and marketing thats what make money, while missing features, and unfulfilled proper implementation of features, well they are just what they are for the most part, a dying request and or thread.
    Cloud threads are of top echelon importance! I am however ready for some cloud dissipation actually and more sunshine being shed on long time perpetual license owners, not just the thought of a cloudy future, but rather some better attention to regular owners. Sadly as the weather people go, these requests and interests are much like weather forecasts, entirely inaccurate, or even worse being held in secrecy hoping we move on to cloudy days. Bring back the sunshine Adobe.
    Welcome to the forum by the way, as you stated it is a great resource for learning and growing your skills with so many skilled individuals around here thats for sure. Get involved and dive into the forum. Sunny or Cloudy at least the forum is by-partial for the most part. ;-)

  • How to stop the spinning ball/pizza that is stalling repairs to project on imovie 09? on macosx10.5.8 using iomega and superspeed ext h.d. as storage for the events and projects archive of a wedding video that has had audio sync problems on all share form

    How to stop the spinning ball/pizza that is stalling repairs to project on imovie 09? on macosx10.5.8 using iomega and superspeed ext h.d. as storage for the events and projects archive of a wedding video that has had audio sync problems on all share formats (iDVD, mp4, and last of all iTunes). The project label now carries signal with yellow triangled exclamation “i tunes out of date”.
    To solve the sync problem I’m following advice and detaching sound from all of the 100 or so short clips.  This operation has been stalled by the spinning ball. Shut down restart has not helped.
    The Project is mounted from Iomega and superspeed ext hd connected to imovie09 on macosx 10.5.8.
    What to do to resume repairs to the audio sync problem and so successfully share for youtube upload?

    How to stop the spinning ball/pizza that is stalling repairs to project on imovie 09? on macosx10.5.8 using iomega and superspeed ext h.d. as storage for the events and projects archive of a wedding video that has had audio sync problems on all share formats (iDVD, mp4, and last of all iTunes). The project label now carries signal with yellow triangled exclamation “i tunes out of date”.
    To solve the sync problem I’m following advice and detaching sound from all of the 100 or so short clips.  This operation has been stalled by the spinning ball. Shut down restart has not helped.
    The Project is mounted from Iomega and superspeed ext hd connected to imovie09 on macosx 10.5.8.
    What to do to resume repairs to the audio sync problem and so successfully share for youtube upload?

  • How to stop the changes made for the BP in CRM not to update in R/3

    Hello Gurus''
    we are in need of help......i have an issue...the issue is
    Wht ever the changes we do in crm , need to be not updated in r/3 ....for example if we change the the language for the BP 100 in CRM, it should not update in R/3
    Where as in our case the data is updateing in R/3
    Here by requesting you all to help me out how to stop the updaation of some changes  which are made in CRM , that should not be in R/3
    Point will be given......
    Regards
    sreeram Raghu

    Hello
    Thanks for ur reply.........
    We have the following business process
    We create BP with role prospect in CRM, once the prospect is ready to buy the product we conver the prospet in to customer and thesame  customer is replicated in R/3 fro sales.
    What i am looking at is for the customer we created in CRM if we change any data that should be updated in r/3..it may be nay like name address ...language....etc.....
    can u help me out...as u told me to unassig/delete the subcription:All Business partner(MESG) under that we have --
    >publication>All BP(MESG)->Replication object-->Bupa_Main
    >Sites-->SQ1_300
    If we do this process does the issue will fix or else we need to do soem thing more...
    Thanks in advance
    Regards
    Sreeram Raghu
    +91-99 94 94 82 72

  • How to stop the waterflow?

    Hi,
    I need to make the water coming from the shower, when shower is clicked.
    And the water should stop after 5 seconds.
    The code is below.
    The water is flowing nicely. But I do not manage to stop it.
    I added a timer, which starts when the shower is clicked. And should stop the waterflow after 5 seconds have passed.
    With the lines
    if (stop = true)
         break;
         trace("break");
    it looks like the for loop is breaking right from the start, from the first second. But not completely, somehow 1 or 2 drops are flowing.
    Without these lines nothing is happening when the time is over (5 seconds from clicking the shower). Water is just flowing.
    Can someone help? How to stop the water flowing after 5 seconds and clean of the array and stage from the waterdrops?
    Many thanks in advance!
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    var WatertropArray: Array = new Array();
    var WaterArea01: MovieClip = new WaterArea();
    var WaterBorder01: MovieClip = new WaterBorder();
    var timer: Timer = new Timer(5000, 1);
    var stopp: Boolean;
    var i: uint;
    Shower.addEventListener(MouseEvent.CLICK, waterFlowStart);
    function waterFlowStart(event: MouseEvent): void
                    addChild(WaterArea01);
                    WaterArea01.x = WaterArea00.x;
                    WaterArea01.y = WaterArea00.y;
                    WaterArea01.alpha = 0;
                    addChild(WaterBorder01);
                    WaterBorder01.x = WaterBorder00.x;
                    WaterBorder01.y = WaterBorder00.y;
                    WaterBorder01.alpha = 0;
                    stopp = false;
                    timer.addEventListener(TimerEvent.TIMER, waterFlowEnd);
                    timer.start();
                    addWaterdrops();
                    Shower.removeEventListener(MouseEvent.CLICK, waterFlowStart);
    function addWaterdrops(): void
                    for(var i: uint = 0; i < 100; i++)
                                   var waterDrop: MovieClip = new Waterdrop();
                                   addChild(waterDrop);
                                   waterDrop.x = Math.round(Math.random() * stage.stageWidth / 1.5);
                                   waterDrop.y = Math.round(Math.random() * stage.stageHeight / 3);
                                   waterDrop.alpha = 0;
                                   waterDrop.rotation = -12;
                                   WatertropArray.push(waterDrop);
                                   trace("waterdrops added");
                                   moveWaterdrops();
    function moveWaterdrops(): void
                    waterDrop00.addEventListener(Event.ENTER_FRAME, waterFlow);
    function waterFlow(event: Event): void
                    for(var i: uint = 0; i < WatertropArray.length; i++)
                                   WatertropArray[i].y += 8;
                                   WatertropArray[i].x += 5;
                                   //trace(i);
                                   if(WatertropArray[i].hitTestObject(WaterArea01))
                                                   WatertropArray[i].alpha = Math.random();
                                                   WatertropArray[i].scaleX = Math.random();
                                                   WatertropArray[i].scaleY = WatertropArray[i].scaleX;
                                   if(WatertropArray[i].hitTestObject(WaterBorder01) || WatertropArray[i].x > stage.stageWidth || WatertropArray[i].y > stage.stageHeight / 2)
                                                   WatertropArray[i].x = Math.round(Math.random() * stage.stageWidth / 1.5);
                                                   WatertropArray[i].y = Math.round(Math.random() * stage.stageHeight / 3);
                                                   WatertropArray[i].alpha = 0;
                                   if(stopp = true)
                                                   break;
                                                   trace("break");
    function waterFlowEnd(event: TimerEvent): void
                    trace("TIME OVER");
                    stopp = true;
                    stoppTrue();
    function stoppTrue(): void
                    for(var i: uint = WatertropArray.length; i > WatertropArray.length; i--)
                                   remove(i);
    function remove(idx: int)
                    removeChild(WatertropArray[idx]);
                    WatertropArray.splice(idx, 1);
                    trace("REMOVED");
                    removeChild(waterDrop00);
                    trace(i);

    thanks again, kglad.
    changed the for-loop and it is reaching now the last functions as well.
    but there is still a but  ... an error message.
    function waterFlowEnd(event: TimerEvent): void
    trace("TIME OVER");
    stopp = true;
    stoppTrue();                                                       // line 106
    function stoppTrue(): void
    for(var i: uint = WatertropArray.length-1; i >= 0; i--)
    trace("stoppTrue");
    remove(i);                                                         // line 115                                                    
    function remove(idx: int)
    removeChild(WatertropArray[idx]);                   // line 123
    WatertropArray.splice(idx, 1);
    trace("REMOVED");
    //removeChild(waterDrop00);
    trace(i);
    and the output panel gives the following (tested with 5 water drops, 5 items in array):
    TIME OVER
    stoppTrue
    REMOVED
    0
    stoppTrue
    REMOVED
    0
    stoppTrue
    REMOVED
    0
    stoppTrue
    REMOVED
    0
    stoppTrue
    REMOVED
    0
    stoppTrue
    TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/removeChild()
    at TitavannisinglisekeelneAS3_fla::MainTimeline/remove()[TitavannisinglisekeelneAS3_fla.Main Timeline::frame1:123]
    at TitavannisinglisekeelneAS3_fla::MainTimeline/stoppTrue()[TitavannisinglisekeelneAS3_fla.M ainTimeline::frame1:115]
    at TitavannisinglisekeelneAS3_fla::MainTimeline/waterFlowEnd()[TitavannisinglisekeelneAS3_fl a.MainTimeline::frame1:106]
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()
    What is that error message trying to tell me?   

  • How to stop the internal batch session

    Hi ,
    How to stop the internal batch session, which is triggered from the program.
    When I execute the program, there is an batch session, which starts processing in parallel with the program, and causes an error message for the program, so the further process is affected.
    I tried finding the session through the Transactions - SM35, SM37. However, I could find any session in my name.
    However, when I try thro SM04, I could find an session with the same error message. But I am not able to end the session.
    Pleas advise.
    Thanks,
    cartesian.

    Go through transaction SM50. In case you have more than one application server (transaction SM51 will show) you can also use SM66 which will show all running processes on all application servers.
    With SM50 you will only see the process running if it is running on the same application server you are logged on to.
    Mark the process and use menu 'Program/Session - End Session' or 'Process - End with or without Core'
    Hope that helps,
    Michael

  • How to stop the auto-start of log reader agent (replication) right after my database is restored?

    I have the scenario where the SQL server is restored (after migration).
    This database has transactional replication set-up on one of the databases. When I do a manual delete and restore of the database, I see that the replication starts right after the publisher and subscriber are restored.
    Replication agents should not start and run before the integrity checks are completed. How to stop the replication from auto starting right after the migration?
    Thanks in advance - Jebah

    Thanks Pradyothana, I have disabled the logreader, distribution agents through sp_update_job in Tsql script. I have also verified that there are no pending transactions to be replicated to the subscriber, I see that the job is still being executed. Is there
    any other way to disable the jobs?
    Steps I followed
    Started with a Working publication and subscription
    Disabled the jobs (log reader and distribution agents)
    Backed up publisher, subscriber, distribution and msdb
    Deleted the publication, subscription, publisher and subscriber
    Restored the publisher, subscriber, distribution and msdb
    Enabled the jobs and executed sp_replrestart
    Observations/Issues
    Replication does not work
    Replication monitor does not show any error
    Jobs are shows as enabled but not started in job monitor
    Not able to start/stop the log reader and synchronization manually.
    I am not sure if I have missed something while restoring the db.
    Thanks in advance

Maybe you are looking for

  • How can I use the print module to print different size images on one large "canvas"?

    How can I use the print module to print different size images on one large "canvas"? An example would be in Photoshop, go to file>new, and create the size paper I want, and move images of different sizes onto it. I was thinking the print module would

  • Anyone noticing their Enter key less sensitive to presses?

    Just got my Macbook about a week ago, absolutely fantastic machine. I've noticed though that sometimes when I press the enter key, the Macbook doesn't always recognize it. I've found I sometimes have to concentrate on pressing the Enter key a bit fir

  • T520 intel HD 3000 (i5-2540m) performance

    Hi: I am running windows XP(32 bit) and integrated graphics on my T520. In the dual screen configuration , the secondary screen seems to be lagging (refreshes slower). It is similar to the slow refreshing seen on a freshly installed XP system without

  • Capturing and logging sound

    Need some help here! I have a sony handycam wide lcd DCR-HC90E PAL with a surround microphone ECM-HQP1. When I capture and log I see that the sound is captured in stereo where it should be in 5.1. May be I do something wrong, but In the user preferen

  • (forte-users) Oggetto: Re: (forte-users) WebSessionManagement

    Luca, This problem has been fixed in WebEnterprise 1.0.E and you can now trap the SessionTimingOut event (see Forte Tech Note 12260). We've just started using it and it seems to work OK. Regards, Mark Carruthers 20th Century Fox Luca Gioppo <Luca.Gio