ExecutorService - ShutdownNow() not shutting down

Here is a sample application:
On Line A, if the simple calculation is set to true, the calculations finish, and the shutdown occurs normally.
If, however, an infinate loop is called (complex calculation), then even when calling shutdownNow() on the pool, the process never exits (which means that there's a running thread). I also tried calling future.cancel() on each task but still, the system keeps running...
I thought that shutdownNow() was supposed to kill any running threads and terminate (?).
package app3;
import java.util.*;
import java.util.concurrent.*;
public class Sample {                                                           // CallableExample
  public static void main(String args[]) throws Exception {
    args = new String[] { "wordOne", "wordTwooooooo", "wordThree" };
    final boolean useSimpleCalculation = false;  // Line A             <---<<    // Change this to false for different behaviour
    System.out.println("Working...");
    long time0 = System.nanoTime();
    ExecutorService pool;
    //pool = Executors.newSingleThreadExecutor();
    pool = Executors.newFixedThreadPool(3);
    Set<Future<Integer>> set = new HashSet<Future<Integer>>();
    //  A. Submit work to be done - parallelize
    System.out.println("Submit work to be done - parallelizing...");
    for (String word: args) {
      // For each word in the argument list, start a new calculation task
      Callable<Integer> callable = new CallableWork(word, useSimpleCalculation);
      Future<Integer> future = pool.submit(callable);
      set.add(future);
    // B. Get and process the results
    System.out.println("Computing sum...");
    int sum = 0;
    for (Future<Integer> future : set) {
      try {
        long     timeout     = 5L;
        TimeUnit timeoutUnit = TimeUnit.SECONDS;
        sum += future.get(timeout, timeoutUnit);     // call with a 5 seconds timeout (more than enough)
      catch (ExecutionException e) {
        System.out.println("Exception: " + e.getMessage());
        System.out.println("Setting length to zero...");
        sum += 0;
      catch(TimeoutException e) {
        System.out.println("This calculation is taking too long! - How would I know which word? Too bad that Future doesn't contain the original Callable data...]");
        future.cancel(true); // Line B
    System.out.printf("The sum of lengths is:  %s%n", sum);
    long time1 = System.nanoTime();
    System.out.println("Completed in " + ((time1-time0)/1000000000L) + " seconds.");
    if (useSimpleCalculation)
      pool.shutdown(); // If you don't do this, the process never finishes because the pool is still running. Also see: pool.shutdownNow()
    else {
      //pool.shutdown();
      //pool.awaitTermination(1, TimeUnit.SECONDS);
      pool.shutdownNow(); // Line C
    System.out.println("Done.");
  // INNER CLASS
  public static class CallableWork implements Callable {
    private String word;
    private boolean simpleCalculation;
    public CallableWork(String word, boolean simpleCalculation) {
      this.word = word;
      this.simpleCalculation = simpleCalculation;
    public Integer call() {
      if (this.simpleCalculation)
        return doSimpleCalculation();
      else
        return doVeryLongRunningCalculation();
    private Integer doSimpleCalculation() {
      /*work*/ try { Thread.currentThread().sleep(2 * 1000); } catch (InterruptedException e) { ; } // continue
      return Integer.valueOf(word.length());
    private Integer doVeryLongRunningCalculation() {
      while(true) {
        // working hard here...
        Thread.currentThread().yield(); // shouldn't do this but it's just an example...
}

I thought that shutdownNow() was supposed to kill any running threads and terminate (?).No. Read the Javadoc.
'Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
'There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so if any tasks mask or fail to respond to interrupts, they may never terminate.'

Similar Messages

  • I connected my iphone 4s that i unlocked for t-mobile. I plugged it into itunes, and it asked me to update to ios6. I accepted the download and update button. it told me it needed 8 hours. i closed my laptop. not shut down. i opened and it wants restorin?

    I connected my iphone 4s that I unlocked for t-mobile. I plugged it into itunes, and it asked me to update to ios6. I accepted the download and update button. It told me it needed 8 hours. I closed my laptop, not shut down. I re-opened the laptop a few hours later, and it wants restoring?? Whats going on?! i want my iphone back! PLEASE HELP. I'M LOST!!! (I synced my iphone to my computer if that helps at all).

    Yes, and, I try to restore. I have the T-Mobile sim card in it just to clarify. It will not let me get passed that, it does not accept the t-mobile sim card. i tried restoring it using wifi, cellular, and i cant get i tunes. I am scared that if i take the tmobile sim card out and put the at&t one in just to complete the restoration process that the iphone will lock again and not read the tmobile sim card, then all my hard work has gone for nothing. ( this whole process was caused by me trying wanting to empty my pictures onto my computer because i did not have any storage space left). <--- that may not be as important, but i included it just because.

  • Can not shut down late 2011 MacBook Pro and turn it back on again without the hard drive disappearing?

    Ok, I have searched for months for an answer to this question to no avail, probably because no one has experienced it before. I am hoping however that you guys can help me figure this one out cause it is driving me nuts! Also, I am not entirely sure what section of the support I should put this under so if I stick it in the wrong place, I apologize.
    Right now my problem is very simple. When I turn off my laptop, and then try to turn it back on, my internal hard drive disappears... and I get the blinking folder with a question mark on it. I have figured out something interesting however. I have an install disk with Ubuntu Linux on it. If I boot into that first, then RESTART the laptop, not shut down and turn back on, it reads the internal hard drive just fine and I can boot as if there is nothing wrong.
    Second part to the problem... If I allow the laptop in either OSX or Windows to go to sleep (aka shut off the hard drive but the computer remains on), when I attempt to wake it up, I am greeted with the usual log in screen of whichever OS I am in, but is frozen and after a few seconds goes black and restarts the computer to find that... Surprise! The hard drive is gone
    I have tried every trick in the book that I can think of, but can not seem to come up with a solution to the problem... I know when the problem happened and if anyone thinks that that will help them figure this out I will type everything I did up till, including the crash that caused this, and my attempted fixes, but I have class right now so only if you guys want it I will type all that out.
    What I am currently running is:
    2011 MacBook Pro 13in screen
    4Gb of Ram
    1TB internal Hard Drive
    OSX 10.11.whatever the newest update is... just updated the other day again.
    Windows 8.1 on BootCamp 5 (yea I know its not supposed to work but it does) again, fully updated
    Ubuntu 13.10 (I think? Doesn't really matter, its just an install disk I use to boot the computer)
    If there is anything else that you guys need me to provide, I can, just simply ask. I can provide as much info as is necessary.

    Sorry it took me so long to write back, But unfortunately this didn't help my issue.
    My uncle and I did a lot of tests on this computer and have narrowed down the location of the problem a little bit.
    We tried to first reset the SMC and the NVRAM as suggested, but the only thing that did was make the fans run on full tilt for the first session after restarting it for some reason. After that we tried re installing OSX over the OSX that was already on the system (not removing any of the files). This also didn't do anything but make refit stop working. Then we moved onto the next task at hand by removing the hard drive entirely and booting it as an external drive from one of the USB ports... as long as you booted it with the options key held down, it worked perfectly fine. Then we put an alternative hard drive into the computer and installed OSX on that. This time there was no trouble booting anything up. Everything seemed to work flawlessly. So we made a backup of my original drive (OSX, Windows, and all) onto an external hard drive and tested booting to it via USB. That again worked perfectly fine and booted right up with no problems. So after that we formatted the original hard drive and reinstated OSX. We then proceeded to transfer all the old files from the backup onto this new installation and LOW AND BEHOLD..... we were back to square one with it refusing to recognize the hard drive again.
    So this basically told us that there appears to be something either wrong with the hard drive, or something got really screwed up in the software along the lines and by me copying all my old files back over, I just ended up bringing the screwed up file back over with it! (despite not copying over any settings of any kind) So I am still extremely confused as to what is going wrong... did some boot sector possibly get screwed up may be?

  • MacBook Pro (10.7.3) not shutting down after updating to latest iTunes

    This is a bit of a strange one, and after searching high and low, I haven't seen any other references to it, so...here goes:
    I'm working on a MacBook Pro (13-inch, Mid 2010) running OS X 10.7.3, and the complaint is this: the system will not shut down or eject a connected iPod (classic) or smartphone (Verizon Android phone) after updating to the latest version of iTunes.
    I've been troubleshooting this for several days now, and I've tried the following:
    1. Created a new admin account and tested from there. No change.
    2. Created a backup image of the hard drive, erased & reinstalled 10.7, created temp admin account - issue resolved, but iTunes library unable to open because it was modified by a newer version of iTunes.
    3. Ran software update to bring system current (as of 20 April 2012)
    4. Issue reappears after software update.
    5. Reinstalled 10.7.3 from Recovery partition.
    6. Again, issue resolved, but unable to open iTunes library modified by newer version.
    7. Update iTunes, issue returns.
    I actually did several variations of the erase & install routine, as well as several admin accounts, but the basic gyst of it is that after updating iTunes, the system hangs at the spinning gear on shutdown every single time.
    The version of iTunes that is reinstalled with Lion is 10.5.1. I don't know which version between that and 10.6.1 is causing the problem.
    Not sure where to go from here, so I figured I'd throw it out to the community.
    Thanks.

    Well, after throwing my hands up in the air, I returned the MacBook Pro and iPod classic to their owner because I'd held onto them for over a week trying to troubleshoot the issue with no success.
    Two days later, she contacted me and told me her iPod was the culprit -- it had some bad sectors on the hard drive. I had thought to check that, but she had data on the iPod that wasn't backed up anywhere, so I back-burnered that until later.
    Glad to see I'm not going insane, though. ;^)

  • My iPod touch will not shut down to the black screen which causes my battery to drain with in an hour?

    My iPod touch will not shut down automatically which causes my battery to drain within hours? HELP

    Have you went to Settings>General>Auto-Lock and specified a shot time?

  • Mac Will Not Shut Down

    I ran Singular past my OS 9.2 drive and it disposed of items that were not duplicates. I rebuilt my system folder from a flash drive. Hard Drive will not shut down. I normally cycle between a drive with OS 10x and my OS 9x in the Startup Disk. Now when I tell it to restart on my OS 10 it will not shut down. I get a Software Update Engine error message with no error code.
    I even reinstalled OS 9.2.2 and it still does it. Even after Norton Utilities.
    To get past it, I option/command/esc to get it to shut off and restart on the other disk.
    Has this happened to any of you?
    Deepsees
    Message was edited by: Deepsees
    Message was edited by: Deepsees

    Thanks for the input. Yes the OS's are on different drives. With all my modeling and animation programs... it would cost me a small fortune to upgrade them, hence OS 9.2.2.
    This all started after telling Singular to dispose of certain duplicated file. It apparently dragged some others out with it. I have a flash drive with the good system 9 that I used to go file by file in the extensions and control panels and made the wiped disk look like the flash drive backup. Corrected a lot except for this not shutting down without using escape. Reinstallation did not stop it.
    The norton is only for 9xx indeed... I am not having trouble with OSX drive at all. When I want to restart to 9xx it does it's restart and into 9xx land. Norton always finds a wall of screwed up blocks and trees... never seemed to be an issue. It raked up the files and fixed what ever these invisible files do. Still same same. We bought the first mac in Jax fl... we have been around this platform ever since. When macs were a bit simpler.. there were only so many things something like this could be. This is the only time I have seen this behavior in a mac.
    I just got in from 500 mile drive.. will go though these responses after a nap.
    Thanks before and after.
    Deepsees
    Message was edited by: Deepsees

  • HP Pavilion P7-1141 will not shut down... Any thoughts?

    Brand new HP Pavilion P7-1141 desktop (AMD A8-3800 quad-core CPU, 8GB RAM, 1TB HDD, Radeon HD 6550D, Windows 7 64-bit) will not shut down properly regardless of what I do - I can press on/off button on the desktop, or choose "shut down" from Windows 7 menu, each time the following happens: Windows shows it's usual "shutting down" screen, then screen goes blank and monitor goes to sleep, but the desktop itself still seems to be working in some unusual mode: fans are rotating - I hear the usual quiet noise from them, the lights on the desktop are on, however, no hard drive activity at all. In this mode, the desktop can't be turned on anymore - I need to press on/off button for a few seconds to turn it off completely or unplug the power cable and plug it back and only after that it can be turned on. Windows will not show any error messages during startup, HP diagnosticks program does not find any issues, no error messages of any kind. I checked power settings in Windows, played with power settings in BIOS without any success. Am I missing something? Any ideas?
    UPDATE: Sleep mode doesn't work as well. When I choose "sleep" from Windows 7 menu, exactly the same thing happens (monitor goes to sleep, fans are rotating, the lights on the desktop are on, no hard drive activity, etc). At least when I choose "restart" it restarts without any problems.

    Hi:
    See if  (re) installing the chipset driver helps.
    http://h10025.www1.hp.com/ewfrf/wc/softwareDownloadIndex?softwareitem=cp-97610-1&cc=us&dlc=en&lc=en&...=
    Paul

  • IMac 27" Not Shutting Down

    Hi,
    recently my iMac has begun not shutting down properly. For the past week or so, I have had numerous attempts at shutting down my iMac. When I begin the shutdown process, i.e. clicking 'shut down', the iMac gets to a white screen with a rotating symbol, like the start up screen but without the Apple Logo, and goes no further. I leave it for an hour, even more and it still does not shut down. What is the problem?
    Thanks

    I notice you're on 10.6.7. You might try upgrading to 10.6.8 and see if that helps. I'd recommend updating using the Combo updater instead of using Software Update.
    You might also try starting your computer while holding Command and V. Then use it for a while, and try to shut down. Additional lines of text should be displayed, and the last few lines may give us some clues as to what's holding things up.

  • HI .. I have a new macmini 2.5 Ghz 10.7.3 Lion, had a problem today ,it froze so I could not shut down using mouse or tablet. used the power switch, when I tried to restart I got audible 'beeps' from it.

    HI ....I have a new macmini 2.5 Ghz 10.7.3 Lion, had a problem today ,it froze so I could not shut down using mouse or tablet pen. used the power switch, when I tried to restart I got audible 'beeps' from it. I managed to restart it but kept getting a message come up on one ot the dual screens ' restart using the power swich to turn it off , then press it again to restart.'
    This worked okay , but now it just keeps freezing whenever I start it up. I thought the issue could be my old Epson Expression 1680 scanner not being compatible , so I have unplugged it. I also had a look at the new memory I installed when I got it, but this seems not be the problem.
    It is connected up to an Eizo Flexscan S2231W using a cable straight into the HDMI input , the other monitor is a small Acer using the VGA into Thunderbolt port.
    When I turn the Eizo screen on first and then press the power button on the mac-mini, I hear the chime then the screen flahes the 'Digital no signal' message on and off for about 30 seconds , then the monitor comes on as normal. But it is still freezing up on me after using it for a while and I am having to use the power switch button to turn it off again.
    Can anyone help please.

    I really don't have an answer for that one. I guess that while trying to get things working correctly, I would use the most basic monitor I had which in your case would be the Eizon using the Thunderbolt port and adaptor.
    When you boot into Safe Mode the startup is quite slow, but you should get the Apple logo and then the spinning gear below it (release the SHIFT key when it appears.) Then after a little more time you should see a gray progress bar appear below the spinning gear. When that disappears the computer will startup to a login screen.

  • Window 8.1 is not shutting down

    Hi
    For my lenovo laptop , Yesterday I updated Windows 8 to 8.1  from  STORE.
    Almost taken 2 hrs . Got the message sucessfully updated . later I made shut down . but its not shutting down ..its keep showing messgae shutting down and process is going on . Almost 2 to 3 hrs kept like that ..but no use . I tried force shut down . later
    showing same  progressing message of shutting down only .
    Task manager ctrl alt del also not working... I do nt know , what to do . please help on this.
    Thank you

    Hi,
    If it only remains in a shutting down process all the time, then we can do nothing, please hold on the power button to power down your PC, then reboot, check whether your PC can function fine. After boot into your PC, please view the event viewer,
    find whether there're some error information recorded under item Windows logs\Application, setup, system.
    View Windows update history under control panel\windows update, see if there're some failed updates, install them again.
    Yolanda Zhu
    TechNet Community Support

  • External hard drive does not shut down

    Hello, When my mini mac goes to sleep my samsung external hard drive does not shut down or dismount properly. when i wake computer i have a error message stating improperly ejected hard drive. It also does not reconize HD until I disconnect and reconnet??? PLEASE HELP Thank you

    My Mini was doing the same thing until I reset the PRAM. With four external drives. They would stop inadvertently with an "improperly ejected" error. Granted two of the drives went bad (6 and 7 years old) but a brand spanking new Seagate and a 3 year old Hitachi drive doing the same. Haven't seen the error since resetting the PRAM.
    If you don't know how to do that, Reboot while holding the Cmd+Opt+P+R keys until your hear the startup chime three times and then release the keys.

  • My macbook pro will not shut down

    Hello,
    please help. I have a brand new computer - MacBook pro - 2.2 GHz, Intel Core i7, Mac OS X 10.6.7. When I bought it, I followed the onscreen instructions and "transferred" my old computer, 4 year old MacBook, onto the new one (my accounts, with all the documents, preferences, etc). Now, for some time, before getting my new computer, I had been experiencing problems on my old one: namely, it was not shutting down and I had to "force" it by pressing the switch. I should have known better than transferring the old comp's settings and accounts onto the new one. I didn't and now my new computer is also not shutting down. Does anyone know how to find where the problem is and how to eliminate it? Do I have to backup all, erase, and reinstall everything or is there a less drastic way to cure my afflicted computer?
    Thank you!
    P.

    Choose Force Quit from the Apple menu and close Outlook from there.
    (123063)

  • MacBook Pro will not shut down

    A principal at my district has a MacBook Pro 15-inch Early 2008 (2.4/2X1GB/200-5400/256VRAM/AG) running OS 10.5.8 that will not shut down. When shut down is chosen, the computer restarts instead of shutting down. It does not matter how shut down is chosen, whether it is from pull down menu, keyboard command, click on shutdown in the login menu, etc. I have tried resetting PRAM, SMC, starting up from a known good system, and run diagnostics applications (which turn up no problems). The only way to get the machine to tunr off is hold the power button down until it shuts off.
    The user complains it also gets very hot when he leaves it sitting open in sleep mode. I have not observed that particular symptom. It also tend to run down the battery faster than it should (battery check shows it to have 80+% of it's original capacity.) But Activity Monitor does not show any unusual activity.
    Any suggestions what I can try next to figure this thing out?
    Thanks.

    On occassion (like tonight) my MacBook Pro will not
    shut down - even when I attempt to force quit. Any
    suggestions?
    Happens here too, but very rarely. In my case it mostly happens late at night when OS X is supposed to run some internal maintenance jobs, maybe some of them do not allow a shutdown?
    Does holding the power button down for approx. 10 seconds work? If yes, then I would not worry about it. If no, there is something seriously odd and I would report it to AppleCare.
    Cheers,
    Uwe

  • The new version of firefox does not shut down when I close the browser it continues running in the background. In addition it opens Adobe Reader for a brief time and then that closes. Everything worked fine before this new version.

    Firefox automatically loaded a new version recently. The new version does not shut down when I close the browser it continues running in the background. In addition it opens Adobe Reader for a brief time and then that closes. Everything worked fine before this new version.

    See "Hang at exit":
    * http://kb.mozillazine.org/Firefox_hangs
    * https://support.mozilla.com/kb/Firefox+hangs

  • Mac Book Pro (OS 10.4.11) WILL NOT SHUT DOWN UNLESS FORCED! STILL PERSISTS!

    My Mac Book Pro 15", 2.33 GHz, 3 GB memory - runninfg Mac OS X 10.4.11 WILL NOT SHUT DOWN UNLESS FORCED! HELP!!!
    When I use the SHUT DOWN command in the Apple Menu - programs close, the screen goes to a blue screen with a revolving time indicator and then remains that way until I FORCE SHUT DOWN by pressing the power button - then after a it makes the sound the screen goes black.
    I searched the forums and tried the suggested fixes: trashing these 2 .plist preferences and reboot.
    Reset your Energy Saver preferences.
    HD > Library > Preferences > SystemConfiguration > com.apple.PowerManagement.plist
    User > Library > Preferences > com.apple.systemuiserver.plist
    this worked for a couple of cycles then the problem retuned/
    Hey, Mac geniuses and wizards - what is going wrong with my macboo

    Have you ever waited and let it do it's thing? I was ready to force mine to quit the other day after waiting 2-3 minutes, and all of sudden, it shut down. I restarted it and then shut it down again. This time it was normal.
    Try this yet before doing an Archive and Install.
    1. Boot from your system CD, run Disk First Aid from your Disk Utility and repair your permissions.
    2. Use a utility like Onyx to clean your system cache out, including your kernel cache. The computer will restart slow right after that, but I keep rebooting the computer about 3 times in a row, and I'm back up to speed.
    -Bmer
    Mac Owners Support Group - Join us @ MacOSG.com
      Mac611 Mobile Mac Support - about.Mac611.com
       iTunes:MacOSG Podcast | YouTube.MacOSG.com
                       An Apple User Group 
    Have an iPhone or iPod touch? Enter Mac611.com in Safari on it for 'mobile Mac support.'

Maybe you are looking for

  • How to diable JDialog on refresh of a data in a tab

    Hi, I have an application which has a tab1 which contains a Jtable.On clicking a cell in Jtable a JDialog appears showing some more info on the cell clicked. Now i want to do this... When i refresh the tab1 the corresponding Jdialog should become emp

  • IC not work with new version of ID

    My designer upgraded to the newest version of inDesign (through CC2014) When I tried to open any files, I got a message that I had to upgrade my IC or the plug ins. The list of plug ins is as follows: Spread.rpln Print.rpln Generic Page Item.rpln Doc

  • Filter songs by rating (on the fly, without smart playlists)

    Is there any way (3rd party app maybe) that would allow you to live filter the displayed/played songs by rating? ie. if I have an artist selected, and all 200 songs are shown by that artist -- I would like to select on the fly to only display/play so

  • G580 Smart Fan Noise PLZ Help me Any One...PLZZZZZZZZZZZZZZzz

    PLZ help me. My lenovo g580 When power on ..Just hearing Noise . Its Smart fan Noise. Plz Help Me Bro...........

  • Based document series need to be copied to target document

    Hi, There are 4 document series for every marketing document as Manufacturing - Series 1, Trading - Series 2, Retail - Series 3, Wholesale - Series 4, Shoppers - Series 5. Now User A is been given permission / authorization for document series 1 and