Best way to stop or kill a thread

hi what would say is the best way to kill a thread in this situation.
1. I have 200 threads
2. Each Thread has a reference stored in a hashtable example;
for( int i=0; i<200; i++){
Thread t = new exThread(i);
hashtable.put(Integer(i) , t );
t.start();
each thread is running in an infinite while loop.
now what would you say is the best way to kill the thread from this parent class.
One thought of mine is to access get the reference and call stop.
example;
Thread tRef = hashtable.get(Integer(100));
tRef.stop();
In the stop method i would clear up whatever it was doing - release resources properly and - when it goes out of the stop scope , i'm guessing it would be destroyed.
Any thoughts or other recommendations ?
Stev

Limeybrit is correct....the way Sun recommends (and which I use) is a boolean at the top of your runnable code. If false, you simply return and don't hit any of the other code in the runnable method.
At the end of your run process, you simply set your Thread to null and wait for the garbage collector to clean up.

Similar Messages

  • What's the best way to stop motion if Windows crashes?

    I am using Visual Basic 6.0 to program some motion moves. I am trying to figure out the best way to stop all motion and turn off all I/Os in the event Windows crashes or stops responding. I have the following:
    NI PCI-7344
    NI UMI-7764
    Windows 2000
    Visual Basic 6.0

    We implemented an interlock solution using two digital lines from the PCI-7344-UMI-7764 to an Opto22 G4PB4, 4 place SSR backplane, with Brentek G4 NO and G4 NC dry contact modules wired in series to supply +24V to a larger relay contactor's coil. Also in series with the relay contactor's coil were a machine guard and machine e-stop switch.
    The Relay contactor supplies 120VAC power to the servo drives and other devices on the machine.
    The LabVIEW application software has to turn one bit on and the other bit off in order to power the relay contactor's coil.
    We found that if the PC power is off or the PC looses power, then the contactor will drop out and kill 120VAC power to the drives.
    However, if the LabVIEW application or the PC hangs then the 7344's digital
    lines remain in the state that they were set before the PC hung.
    To totally failsafe this also required a watchdog timer relay where the LabVIEW application has to keep
    resetting the watchdog relay with a heartbeat pulse.
    If the LabVIEW application fails to turn on it's heartbeat pulse then the watchdog timer relay will also
    kill power to the drives.
    There are probably better -simpler solutions to be applied but this worked for us.

  • What is the best way to stop parallel loops at the same time, from any loop?

    If there is a vi with two or more parallel while loops, what would be a good method to simultaneously stop parallel loop execution, from any of the parallel loops? My intent was to try and do this without local variables, so I used notifiers. This seems like an ok method for two loops, but how about for n loops?
    In addition, my code has a flaw. I use an OR block to compare the stop status of each of the loops. This works fine most of the time, but if both loops are triggered to stop at the same time,the boolean result will be false, causing the loops to never stop. How can this be avoided?
    Thanks,
    Curt
    Attachments:
    parallel_loop_w-stop.vi ‏54 KB

    I think you have the right idea, notifiers are one of the better ways to stop parallel loops. You can simplify things by using 1 notifier for everything. I modified your VI to use 1 notifier, it will set the notifier to True ONLY if the loop is stopping, then it stops. The other loop will read the notifier status, and stop based on it the next time it executes.
    I also changed the second loop to stop and notify if it has an error (that is usually a good idea, especally if you have I/O or other things that can cause problems)
    I also changed the switch mechanical action, that will eliminate the problems for your second question.
    The VI's attached are written in Labview 7.0
    P.S. If you have 7.1, the Queues are polymorphic, meaning that the typecast operat
    ions are NOT needed!
    Attachments:
    parallel_loop_w-stop7_0.vi ‏45 KB

  • What is the best way to stop the depreciation of an asset

    I had tried ticking the asset shutdown field, but it didn't works. I change the depreciation key , e.g. 0000-zero depreciation, it works, however i do not know what is the implication of doing this.
    What is the best option to stop depreciation of an asset?
    Thanks.
    Best Regards,
    Roberto Sayo

    Hi,
    No depreciation for a period of time
    If you have an asset which would not be used for production purposes for next six months as the plant is being closed.
    Therefore you don't want to retire the asset and neither do you want depreciation to be carried out during these six months period.
    Once the plant is opened, from then on, you want to execute the depreciation run.
    You can utilize the Asset Shutdown feature on the Time-dependent tab of the asset master record.
    Select the Asset Shutdown checkbox - create a time interval - Save.
    If you cannot find the checkbox, it could be hidden :-
    In AS02 click Environment -> Screen Layout -> Master data
    Select the Screen Layout and click Logical Field groups
    Select 3 - Time-dependent and click Field group rules
    Tick Opt, Mnno and Sbno - Save
    Optionally,
    you can set the Depreciation key in the Deprecation Area Tab.
    You can also change the depreciation key to '0000' (No depreciation and no interest) for each of your depreciation books. Just make sure you have run depreciation up through the current month before doing so. When you are ready to put the asset back into service, reset the keys to their original values. The system will calculate no depreciation during the months where you have the key set to '0000'.

  • Is there a better way to stop a Method than Thread.stop()?

    First my basic problem. In one of my programs I am using constraint solver. I call the constraint solver with a set of constraints and it returns a Map with a satisfying assignment. In most cases this works in acceptable time ( less than 1 second). But in some cases it may take hours. Currently I am running the function in a Thread and using Thread.stop(). This look like that:
         public Map<String, Object> getConcreteModel(
                   Collection<Constraint> constraints) {
              WorkingThread t=new WorkingThread(constraints);
              t.setName("WorkingThread");
              t.start();
              try {
                   t.join(Configuration.MAX_TIME);
              } catch (InterruptedException e) {
              if(t.isAlive()){
                   t.stop();
              return t.getSolution();
         }where t.getSolution(); returns null if the Thread was interrupted.
    Unfortunately this sometimes crashes the JVM with:
    # A fatal error has been detected by the Java Runtime Environment:
    #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006dbeb527, pid=5788, tid=4188
    # JRE version: 6.0_18-b07
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (16.0-b13 mixed mode windows-amd64 )
    # Problematic frame:
    # V  [jvm.dll+0x3fb527]
    # An error report file with more information is saved as:
    # F:\Eigene Dateien\Masterarbeit\workspace\JPF-Listener-Test\hs_err_pid5788.log
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    #Does anyone knows a better way to do it?
    Thank you in advance.
    Note 1: the Constraint solver is a Third Party tool and changing it is unfeasible. (I have tried it already)
    Note 2: Using Thread.stop(Throwable t) only chances the error message.

    In case somebody have the same problem here my code which solves the problem. Note it requires to parameters and the result to be serializable.
    The Class which starts to Process:
    public class Solver{
         public Map<String, Object> getConcreteModel(
                   Collection<Constraint> constraints) {
                   try
                        Process p=Runtime.getRuntime().exec(...); //do not forget the classpath
                        new TimeOut(Configuration.MAX_TIME, p).start();
                        ObjectOutputStream out=new ObjectOutputStream(p.getOutputStream());
                        new ErrReader(p.getErrorStream()).start();//not that std.err fills up the pipe
                        out.writeObject(constraints);
                        out.flush();
                        ObjectInputStream in=new ObjectInputStream(p.getInputStream());
                        return (Map<String, Object>) in.readObject();
                   catch(IOException e)
                        return null;
                   } catch (ClassNotFoundException e) {
                        //should not happen
                        return null;
         // For running in a own process
         static private class TimeOut extends Thread
              private int time;
              private Process p;
              public TimeOut(int time, Process p)
                   this.time=time;
                   this.p=p;
              @Override
              public void run() {
                   synchronized (this) {
                        try {
                             this.wait(time);
                        } catch (InterruptedException e) {
                   p.destroy();
         static class ErrReader extends Thread
             InputStream is;
             ErrReader(InputStream is)
                 this.is = is;
                 this.setDaemon(true);
             public void run()
                 try
                     InputStreamReader isr = new InputStreamReader(is);
                     BufferedReader br = new BufferedReader(isr);
                     String line=null;
                     while ( (line = br.readLine()) != null)
                         System.err.println(line);   
                     } catch (IOException ioe)
                         ioe.printStackTrace(); 
    }And the class which executet the Program
    public class SolverProcess {
          * @param args ignored
         public static void main(String[] args){
              try {
                   ObjectInputStream in =new ObjectInputStream(System.in);
                   SolverProcess p=new SolverProcess();
                   p.constraints=(Collection<Constraint>) in.readObject();
                   p.compute();
                   ObjectOutputStream out=new ObjectOutputStream(System.out);
                   out.writeObject(p.solution);
                   out.flush();
              } catch (Exception e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              //System.err.println("solved");
              System.exit(0);
         private Map<String, Object> solution=null;
         private Collection<Constraint> constraints;
           private void compute()
    }

  • Best way to schedule lots of small threads

    Hello,
    I'm working on a large set of data and trying to split up the job between multiple threads, to be more exact about 1000 threads.
    The maximum number of threads I can run simultaneously is defined by MAX_THREADS.
    To be most efficient I would need to know when a thread finishes to start the next one.
    I've tried a solution where I start MAX_THREADS, then sleep for a certain time, then check if all threads are still running and start new threads in place of the ones finished. I found it really hard to figure out a good timing for polling the threads.
    My next solution would be to create MAX_THREADS number of helper threads that kick off a thread from a pool, then join them and start new ones as those finish.
    Another idea is to create a listener that would be activated when a certain thread finishes so it can kick off a new thread.
    Could anyone suggest a good solution for this problem? Or best practice?
    Thanks,
    Lajos

    This ThreadPool approach is wrong puckstopper31. The
    concept of a ThreadPool is to re-use the Threads that
    have already been allocated. When a job is done, a
    thread shouldn't removed from the ThreadPool, unless
    some configurations specify that there shouldn't be
    more than a certain amount of idling Threads.
    Otherwise, you're getting rid of one of the most
    important reasons for using a ThreadPool: reducing
    the overhead of Thread creation and destruction.I'm not disagreeing that this is one way to use a thread pool, but it is not the ONLY way to use a thread pool. The implementation I outlined works extremely well for what it is designed to do.
    PS.

  • What's the best way to stop pop-ups, add-ons and annoying ads?

    i've tried a lot of things to get rid of all these annoying ads and pop-ups and nothing is 100% working. could anyone please help me out with this on chrome or safari?

    You may have installed one of the common types of ad-injection malware. Follow the instructions on this Apple Support page to remove it.
    Back up all data before making any changes.
    One of the steps in the article is to remove malicious Safari extensions. Do the equivalent in the Chrome and Firefox browsers, if you use either of those. If Safari crashes on launch, skip that step and come back to it after you've done everything else.
    If you don't find any of the files or extensions listed, or if removing them doesn't stop the ad injection, ask for further instructions.
    Make sure you don't repeat the mistake that led you to install the malware. It may have come from an Internet cesspit such as "Softonic" or "CNET Download." Never visit either of those sites again. You might also have downloaded it from an ad in a page on some other site. The ad would probably have included a large green button labeled "Download" or "Download Now" in white letters. The button is designed to confuse people who intend to download something else on the same page. If you ever download a file that isn't obviously what you expected, delete it immediately.
    Malware is also found on websites that traffic in pirated content such as video. If you, or anyone else who uses the computer, visit such sites and follow prompts to install software, you can expect more of the same, and worse, to follow. Never install any software that you downloaded from a bittorrent, or that was downloaded by someone else from an unknown source.
    In the Security & Privacy pane of System Preferences, select the General tab. The radio button marked Anywhere  should not be selected. If it is, click the lock icon to unlock the settings, then select one of the other buttons. After that, don't ignore a warning that you are about to run or install an application from an unknown developer.
    Still in System Preferences, open the App Store or Software Update pane and check the box marked
              Install system data files and security updates
    if it's not already checked.

  • Best way to stop spam being entered by form

    Hi there All,
    Sorry this is a bit of a general question and I dare say
    there is no cut and
    dried answer.
    I produce sites for automotive dealers using classic .asp.
    Most of, not all
    sites have feedback forms for which I've been using client
    side validation.
    But the dealers have been getting increasing amounts of spam
    which looks
    like someone has sat and entered via the form. IE. All the
    mandatory fields
    are entered and comply with the validation.
    I've recently installed a html to email server component on
    our server call
    jMail
    http://www.dimac.net/default2.asp?M=Products/MenuCOM.asp&P=Products/w3JMail/start.htm),
    the upshot being I can now write some sort of server side
    validation. The
    problem is I can't think of a way to validate against
    someone, or something,
    inputting what appears to valid entries and then a load of
    spam.... if you
    see what I mean.
    I suspect the people spamming my customers are actually
    robots, that have
    analysed how my feedback forms work and which entries must be
    filled in and
    with what. In which case the only way I can see of guarding
    against it is to
    use that "twisted numbers and letters" thing, where you get a
    distorted
    series of characters which must be entered correctly in order
    for the forms
    content to be accepted.
    So, 2 questions really, is that the only way to do it?
    And,
    Would anybody know where I could get some info on how to do
    it please?
    Major sized thanks in advance.
    @ndyB

    Thanks for the info Kim.
    @ndyB
    "Kim" <[email protected]> wrote in message
    news:eutjth$g41$[email protected]..
    > Hi Andy,
    >
    > This might give you an idea
    >
    http://www.geekministry.com/blog_article.php?id=93
    >
    > The zip wont work for you as you're using asp but you'll
    get the idea...
    > or google captcha
    >
    > Kim
    >
    > @ndyB skrev:
    >> Hi there All,
    >>
    >> Sorry this is a bit of a general question and I dare
    say there is no cut
    >> and dried answer.
    >>
    >> I produce sites for automotive dealers using classic
    .asp. Most of, not
    >> all sites have feedback forms for which I've been
    using client side
    >> validation. But the dealers have been getting
    increasing amounts of spam
    >> which looks like someone has sat and entered via the
    form. IE. All the
    >> mandatory fields are entered and comply with the
    validation.
    >>
    >> I've recently installed a html to email server
    component on our server
    >> call jMail
    >> (
    http://www.dimac.net/default2.asp?M=Products/MenuCOM.asp&P=Products/w3JMail/start.htm),
    >> the upshot being I can now write some sort of server
    side validation. The
    >> problem is I can't think of a way to validate
    against someone, or
    >> something, inputting what appears to valid entries
    and then a load of
    >> spam.... if you see what I mean.
    >>
    >> I suspect the people spamming my customers are
    actually robots, that have
    >> analysed how my feedback forms work and which
    entries must be filled in
    >> and with what. In which case the only way I can see
    of guarding against
    >> it is to use that "twisted numbers and letters"
    thing, where you get a
    >> distorted series of characters which must be entered
    correctly in order
    >> for the forms content to be accepted.
    >>
    >> So, 2 questions really, is that the only way to do
    it?
    >> And,
    >> Would anybody know where I could get some info on
    how to do it please?
    >>
    >> Major sized thanks in advance.
    >>
    >> @ndyB
    >>
    >
    > --
    > Kim
    > ---------------------------
    >
    http://www.geekministry.com

  • Best way to stop the screen from scratching?

    Hi, under 2 months back I bought a 3G iPod. I love it to death, even more then the 4Gs. My only problem is, the screen keeps scratching! Are any good, cheap, screen protectors on the market?
    I haven't ever abused it, it scratches with something in my pockets. It kinda annoys me.
    Thanks,
    -Patrick, eJoystick

    Hi, you might want to check out some Websites like 3btech.net or monoprice.com
    They might have some cheap film protection for your iPod screen. If you want to get something better to protect the iPod and the screen, you might want to check out iFrogz(tm) nanowrapz, which is a protective silicon case for your iPod Nano 3rd Generation and it includes a protection film for the screen, too. The price is about $12 or cheaper.

  • 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.

  • Elegant way of stopping a looping application?

    Hi all!
    What would be the best way to stop an application that works with a loop
    (checking files every x seconds or listening on a TCP port for example).
    I start the application using a shell script and kill it with it's process-ID.
    Problem is if there are any database connections open I have no time left
    to close them if I kill the VM.
    Any suggestions for a 'clean' shutdown?

    Killing it like that is by definition an abnormal termination, of course. You'll need to redesign the application so that it "knows" when it's time to quit. Maybe this isn't what you're getting at - this is basic stuff.
    while (keepWorking)
      // do your stuff
      // if you get a message saying time to quit then set keepWorking = false
      // for example, if you're listening to a port, maybe something should send a "quit" message to the port
    // program continues here, to clean up and exit

  • Best way to prevent automated/spam form filling? ASP/VB

    Hi,
    I wanted to ask what your advice would be with regard the
    best way of
    preventing the automated submission of forms on a web site?
    We have tried using form validation, but it seems that the
    spammers have
    already sussed this and are submitting valid data, albeit it
    is usually
    something along the lines of:
    Name: wuehtasdgadfl
    Title: ahadlf
    Address: audhliuhwerlj
    City: akjsdhiehrlj
    Email: [email protected]
    What is the best way to stop this happening? Or at least
    reduce it!
    Much appreciated.
    Regards
    Nath.

    > When you say "Test the form content server side..." is
    that what the built
    > in Dreamweaver behaviour (validate form) does?
    No. That's client-side validation using javascript. It's
    vulnerable in
    that disabling js in the browser will still allow you to
    submit the form,
    but will not do any validation. The automated bots that spam
    your forms
    don't do the validation when it's client side.
    By server-side validation, I mean to submit the form to an
    ASP, PHP, CF,
    CGI, etc., script that actually examines the contents of each
    field and
    decides whether to send the email.
    > With the sum field, do you mean that you'd ask the user
    to enter a number?
    Yes. See how I have done it here -
    http://great-web-sights.com/g_contactus.asp
    > If so, what happens when the spammers suss that out and
    start submitting
    > the correct number?
    If the 'spammer' is a human reading the instructions and
    submitting the
    form, you can't do anything about it. I think that's not the
    case with
    these things though.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Nathon Jones" <[email protected]> wrote in
    message
    news:[email protected]...
    > Hi Murray,
    >
    > When you say "Test the form content server side..." is
    that what the built
    > in Dreamweaver behaviour (validate form) does?
    > If not, would you have a link to a tutorial on how to do
    that (for
    > ASP/VB)?
    >
    > With the sum field, do you mean that you'd ask the user
    to enter a number?
    > If so, what happens when the spammers suss that out and
    start submitting
    > the correct number?
    >
    > Much appreciated
    > Regards
    > Nath.
    >
    > "Murray *ACE*" <[email protected]>
    wrote in message
    > news:[email protected]...
    >> Test the form content server side and always have a
    field like this -
    >>
    >> Please enter the sum of 3 and five minus one:
    >>
    >> If that field doesn't contain "7", don't send the
    email....
    >>
    >> --
    >> Murray --- ICQ 71997575
    >> Adobe Community Expert
    >> (If you *MUST* email me, don't LAUGH when you do
    so!)
    >> ==================
    >>
    http://www.dreamweavermx-templates.com
    - Template Triage!
    >>
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    >>
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    >>
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    >> ==================
    >>
    >>
    >> "Nathon Jones" <[email protected]>
    wrote in message
    >> news:[email protected]...
    >>> Hi,
    >>>
    >>> I wanted to ask what your advice would be with
    regard the best way of
    >>> preventing the automated submission of forms on
    a web site?
    >>>
    >>> We have tried using form validation, but it
    seems that the spammers have
    >>> already sussed this and are submitting valid
    data, albeit it is usually
    >>> something along the lines of:
    >>>
    >>> Name: wuehtasdgadfl
    >>> Title: ahadlf
    >>> Address: audhliuhwerlj
    >>> City: akjsdhiehrlj
    >>> Email: [email protected]
    >>>
    >>> What is the best way to stop this happening? Or
    at least reduce it!
    >>>
    >>> Much appreciated.
    >>> Regards
    >>> Nath.
    >>>
    >>
    >>
    >
    >

  • What is the best way to kill/stop a data load?

    Hi.
    What is the best way to kill/stop a data load?
    I have a data load from my QA R/3 system that is extracting 115.000.000+ records. The problem is that the selection in the function module used in the data source does not work, and the problem was not detected because of the nature of the data on the development system.
    I could kill processes owned by my background user (on both R/3 and BW) but I risk killing other loads, and sometimes the job seems to restart if I just try to kill processes. If I remove transactional RFCs in SM58 the load does not terminate; I only skip one or more datapackages. I have also tried to change the QM-status in the monitor to red, but that does not stop the load either...
    So isn't there a nice fool-proof way of stopping a dataload?
    Best regards,
    Christian Frier

    Hi,
    There r 2 ways to kill the job.
    One is using transation RSMO locate the job and display the status tab double click on the yellow light that is shown on the line total, a pop will come 'set overall status ' is displayed select the desired status that is red and save it. Then return to the monitor page and select the header tab double ckick on the data target right click and then goto 'manage',there should be request sitting there probably with yellow lights , highlight the line with the faulty request click the delete button then click refresh button.
    Second is 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)
    hope it is clear.
    Regards-
    Siddhu

  • What's the best way to cleanly stop Goldengate?

    For routine maintenance/upgrades what's the best way to cleanly stop GoldenGate? I don't want to wait endlessly. I use this currently and seen no issues :-
    stop er *!
    kill er *!
    stop manager!
    Thanks,
    Shankar

    shiyer wrote:
    For routine maintenance/upgrades what's the best way to cleanly stop GoldenGate? I don't want to wait endlessly. I use this currently and seen no issues :-
    stop er *!
    kill er *!
    stop manager!
    For routine maintenance/upgrades, just {noformat} "stop er *" {noformat} should be preferred; and when all processes are stopped, mgr can (optionally) be stopped. If you really are waiting endlessly for this to return, the real question is "why": then, perhaps there are other parameters that can be adjusted to make GG stop more quickly. (On the other hand, {noformat} "stop mgr!" {noformat} is harmless, the "!" simply prevents it from asking "are you sure?" before stopping the process.)
    I really wouldn't use "kill" unless you really have a good reason to (and the reason itself requiring the process to be killed should be analyzed & resolved). To "kill" a process shouldn't cause data loss (GG always maintains checkpoints to prevent this) -- but still it seems unnecessary, unless there really is something that should be killed. (Aside: I mean, I can kill -9 / "force quit" my browser and/or 'halt' my laptop every time as well, and it would probably be "faster" to -- but it can cause issues (and wasted time) upon restart: i.e., fsck, recover sessions, whatever. Same basic idea, imo.)
    There's a reason there are different commands to 'stop' processes (stop vs. stop! vs. kill). Just for example, "stop replicat !" causes current transactions to be rolled back; there typically is no reason for this, you'll just restart that txn when the process is restarted; might as well let the current one finish. And "kill extract" (I believe) will not warn about potentially "long running transactions" that can cause (painful) issues at startup (missing old archive logs, etc). There are probably other examples, as well.
    So if this really is "routine", then "stop", don't "stop!" or "kill". If there are long delays, see why first & see if they can be addressed independently. (This really is just a stock answer for a generic question, it would be irresponsible for me to answer otherwise :-) )

  • Best way for a thread to wait without busy-waiting

    Hi!
    I have a thread that has nothing to do but to monitor the status of a variable
    public static boolean askToClose. This variable is set by other
    threads to indicate that this thread should stop now. But I don't want the thread
    to busy-wait like in this piece of code :
    public void run() {
         while (!askToClose) {
              Thread.sleep(1000);
         cleanAndStop();     
    }I'm new to Thread programming in Java so I'm not sure what's the best way to wait
    for an event without busy-waiting. I've tried using interruption instead of
    monitoring for the boolean variable :
    public void run() {
         try {
              synchronized (this) {
                   System.out.println("WAITING");
                   wait(0);
         catch (InterruptedException e) {
              System.out.println("INTERRUPTED !");
         cleanAndStop();     
    }and the other threads would simply call myThread.interrupt() instead of setting
    askToClose = true;And I've also used a LinkedBlockingQueue :
    public static LinkedBlockingQueue q = new LinkedBlockingQueue();
    public void run() {
         try {
              q.take();//Waiting
         catch (InterruptedException e) {}
         cleanAndStop();     
    }and on the other threads :
    MyThread.q.add(new Object());Which one is the best solution ? Do I really avoid busy waiting with this code? Is
    there a better way of doing this?
    Thx for your help !

    Your wait() based solution is OK, except that the other thread should
    use
    synchronized()
      notify();
    }

Maybe you are looking for