Why can't I interrupt the main thread from a child thread with this code?

I am trying to find an elegant way for a child thread (spawned from a main thread) to stop what its doing and tell the main thread something went wrong. I thought that if I invoke mainThread.interrupt() from the child thread by giving the child thread a reference to the main thread, that would do the trick. But it doesn't work all the time. I want to know why. Here's my code below:
The main class:
* IF YOU RUN THIS OFTEN ENOUGH, YOU'LL NOTICE THE "Child Please!" MESSAGE NOT SHOW AT SOME POINT. WHY?
public class InterruptingParentFromChildThread
     public static void main( String args[] )
          Thread child = new Thread( new ChildThread( Thread.currentThread() ) );
          child.start();
          try
               child.join();
          catch( InterruptedException e )
// THE LINE BELOW DOESN'T GET PRINTED EVERY SINGLE TIME ALTHOUGH IT WORKS MOST TIMES, WHY?
               System.out.println( "Child please!" );
          System.out.println( "ALL DONE!" );
The class for the child thread:
public class ChildThread implements Runnable
     Thread mParent;
     public ChildThread( Thread inParent )
          mParent = inParent;
     public void run()
          System.out.println( "In child thread." );
          System.out.println( "Let's interrupt the parent thread now." );
          // THE COMMENTED OUT LINE BELOW, IF UNCOMMENTED, DOESN'T INVOKE InterruptedException THAT CAN BE CAUGHT IN THE MAIN CLASS' CATCH BLOCK, WHY?
          //Thread.currentThread().interrupt();
          // THIS LINE BELOW ONLY WORKS SOMETIMES, WHY?
          mParent.interrupt();
}

EJP wrote:
I'm not convinced about that. The wording in join() suggests that, but the wording in interrupt() definitely does not.Thread.join() doesn't really provide much in the way of details, but Object.wait() does:
"throws InterruptedException - if any thread interrupted the current thread +before+ or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown."
every jdk method i've used which throws InterruptedException will always throw if entered while a thread is currently interrupted. admitted, i rarely use Thread.join(), so it's possible that method could be different. however, that makes the thread interruption far less useful if it's required to hit the thread while it's already paused.
a simple test with Thread.sleep() confirms my expected behavior (sleep will throw):
Thread.currentThread().interrupt();
Thread.sleep(1000L);

Similar Messages

  • I have upgrade ios 6 to ios7 on my iphone 5.  I do NOT like it.  I want to come back to the previosu version.  why is it so complicated.  Why can I not find the instruction strait from apple? This is the worst possible upgrade ever.

    I have upgrade ios 6 to ios7 on my iphone 5.  I do NOT like it at all.   I want to come back to the previous version.  why is it so complicated? Why can I not find the instruction strait from apple? This is the worst possible upgrade ever.  It make me think of when ericsson got sold to Sony....drastic PC change.
    I would like to have simple instruction on how to downgrade.
    It feel like a change that I did not ask for , ok I push the upgrade buttom, but really this is the worst update aver!
    HELP!

    iPhone User Guide (For iOS 7 Software)Sep 20, 2013 - 23 MB

  • HT201263 My iPad 1 can only be updated to iOS 5 yet most apps run on iOS 7. Why can't I make the update on my iPad 1? Is this so I buy another iPad 2+? Now why would I want to buy something that will be obsolete in a few years?

    My iPad 1 can only be updated to iOS 5 yet most apps run on iOS 7. Why can't I make the update on my iPad 1? Is this so I buy another iPad 2+? Now why would I want to buy something that will be obsolete in a few years?  I really want to purchase an Live TV plan yet I need iOS 7 to run most TV apps.
    Can Apple tell me why my iPad 1 is obsolete?
    g

    It's not obsolete as much as the first gen simply lacks the power to run the newer operating systems. IT doesn't have enough RAM. If someone managed to hack it to get iOS 6 or 7 on there they'd just have a slow, boggy and unresponsive device. (think putting windows 7 on an old laptop.
    Unfortunately software moves faster than hardware. Every thing goes obsolete. I've had my ipad 2 for two and a half years now and I know it only has so much longer left to it too. Just the 'joys' of advancing technology.

  • Why can't I use the 16GB DDR3 System Memory (2 Dimm) with 24GB flash Hard Drive Acceleration Cache?

    I tried to customize the Envy 15t but I can't proceed on upgrading the following.
    Error
    24GB SSD Acceleration Cache requires purchase only up to 8GB System Memory. 
    Why can't I use the 16GB DDR3 System Memory (2 Dimm) with 24GB flash Hard Drive Acceleration Cache?
    Can HP explain this to me? or any one? please

    Hi,
    The 24Gb cache drive will store manything and normally it will need at least twice the size (capacity) of RAM. Double 16Gb is 32Gb therefore 24Gb is not big enough.
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • HT1657 My download keeps freezing, and I have to buy it over and over again and it wastes money. I have now rented my movie 4 times and it still won't finish downloading. Why can't I get the rental for free if it keeps doing this?

    MY DOWNLOAD KEEPS FREEZING AND I HAVE TO KEEP BUYING IT OVER AND OVER AGAIN. IT'S WASTING MY MONEY. I HAVE NOW RENTED MY MOVIE 4 TIMES AND IT STILL WON'T FINISH DOWNLOADING. WHY CAN'T I GET THE RENTAL FOR FREE IF IT KEEPS DOING THIS? CAN YOU PLEASE HELP? THANK YOU.

    Please turn off your caps lock.  All caps indicates shouting, is considered rude and is difficult to read.  Many will not read such posts.
    If it doesn't finish downloading then just click Store>Check For Available Downloads
    There is no need to keep re-buying it.

  • HT204088 Why can't I see the purchase history from the ipad? I mean, I can buy apps and in game content directly from my iPad, but I have have to install iTunes on my PC to see the purchase history? What kind of deal is that?

    Why can't I see the purchase history from the ipad? I mean, I can buy apps and in game content directly from my iPad, but I have have to install iTunes on my PC to see the purchase history? What kind of deal is that?

    Welcome to Apple Communities
    You don't need to install iTunes for the purchase history. You can see it in your iPad (iTunes > Purchased), but you need to install it if you want the order numbers

  • Why can't I accept the beginning agreement button? unable to use this program without it.

    I downloaded the adobe reader X for windows vista but can't get past the agreement page!!!! It won't scroll down to the bottom where the accept button is.  How can I use this program if I can't get to the agreement button??????/

    See also http://helpx.adobe.com/acrobat/kb/cant-click-accept-acrobat-reader.html

  • Why can't I use the Width tool on lines I drew with the Paintbrush tool?

    I have drawn a shape using the Paintbrush tool's new smooth fidelity with a 3 pt stroke.  But when I go to use the Varible Width tool it want allow me to modify the line.  what am I doing wrong?  Is this even possible?

    Thanks.  That seems unfortunate.
    Bruce Burton
    Kiku Obata & Company
    6161 Delmar Blvd., Suite 200, St. Louis, MO 63112
    Direct 314.505.8427  Fax 314.361.4716
    www.kikuobata.com

  • Why can't we just have separate log ins and be done with this nonsense?

    As the topic says...
    This common login is supposed to be one reason why Adobe can't implement NNTP. But what function does it serve? I've commented in another thread, and below is more or less, what i said there...
    That, i think, was the most assinine idea anyone ever came up with. I see no reason for not having separate log ins for store and forums / downloads. In fact, i can't think of one good reason to combine the two.
    If i were a user of the Adobe store, i would definitely prefer to have a separate login and password for that area. I think most people would. I see a lot of aliases in the forums. In the store, you'd want to use your real name for tax and audit purposes. Moreover, what's to stop people creating two identities anyway? So, the whole purpose of a common id is meaningless.
    Am sure, that even at this stage, it wouldn't be too difficult to separate the two. For instance, whenever i open the forums i see a welcome at the top of the screen. Right above 'Home'. Yet, i still have to login to the forums... what give? Idiotic.
    Adding to the above, doing away with this single log in would also mean an end to this frustration of suddenly getting logged off, randomly staying logged in, etc., etc.

    jochemd wrote:
    JayJhabrix wrote on 2009-05-24 08:05:
    This common login is supposed to be one reason why Adobe can't implement NNTP.  But what function does it serve?
    It reduces the number of accounts people have to remember. I am very
    glad I do not have to have separate accounts for the Adobe site, the
    WebX forums, the Fusetalk forums, the Acrobat.com site, the
    Photoshop.com site, the trainers portal, the Community portal, the
    Partner portal etc.
    I remember the days those were all different accounts and I am glad they
    are gone. I can't wait until the prerelease site and the EDS site are
    fixed to work with the Adobe ID as well.
    In my reply to Kaguyen, I wrote:
    I agree that having a single loging procedure for all the forums was logic and necessary. However, I still completely fail to understand the logic behind tying the Adobe Store and the Forums login procedures. By its very nature, the former needs strong security measures that are not only unnecessary, but also completely absurd in a public forum. I gladly accept being logged out of my bank account and of the  Adobe Store after a fixed period of inactivity. However, I see no reason for, and strongly object to, being logged out of any public forum after any period of time.
    I would very much prefer remembering separate login data for each than been constantly logged out of the forums. Even more so as the login procedures currently in use were not tested properly before being implemented, and logouts occur unpredictably, including many cases where the user is active. Following your logic, why not have just one username and password for everything, including bank accounts, large stores such as Amazon, taxing purposes, etc?
    But separating them just isn't going to happen. And you know it isn't,
    because it isn't a technical decision but a policy choice. So I would
    very much appreciate if you stopped whining and detracting attention
    from issues that do stand a chance of changing.
    Jochem
    Now this is really a gem. I do hope you are not a member of the Adobe higher quarters, and that you are not officially speaking for Adobe, because a company that isn't able to recognize and correct a bad policy decision is doomed. Also, I hope you are willing to explain to us mere mortals which of the very many issues people are (in your words) whining about do stand a chance, however slight, of changing.

  • Why can't I see the left most tab in a window with FF6?

    My problem is that when I upgraded to FF6 and started firefox in some windows the left most tab is hidden, what do I need to do to be able to see all of my tabs? I did not have this problem with FF4 only the last version of FF5 and FF6. I reverted back to FF4 and was reluctant to upgrade because of this issue. I can get to the tab by going to tab group but I see this as an unnecessary step. perhaps you should stop having lunch with your microsoft neighbors.

    I think you would have had the same problem in 3.6. Anyway the tabs do not narrow down instead they scroll off the left side or off of the right side and you can only show 5 or 6 tabs depending on how wide you have your window.
    The following three styles will help you to work with tabs, the first one will help with your specific problem. Be sure tho read the write-up because you will need some configuration changes as well. The one with the tab borders will need an extension from the MozillaZine site.
    * Tabs Bar Minimal Size - Themes and Skins for Browser<br>http://userstyles.org/styles/9043
    * Tab Color Underscoring active/read/unread (Fx3.6 ) - Themes and Skins for Browser<br>http://userstyles.org/styles/24728/tab-color-underscoring-active-read-unread-fx3-6
    * Tabs, Enlarge list-all-tabs button (DM*) - Themes and Skins for Browser <br>http://userstyles.org/styles/18553

  • Why can't I get the playlist/songs from my computer to my iphone?

    why cant i get my playlist/songs from my computer to my iphone 5

    Inelligible songs include any that are over 200MB, are encoded at 96 Kbps or less, or were purchased from a service other than the iTunes store and contain DRM.

  • Why can't I access the iBooks store from my iPad?

    The Store link in my iStore app is greyed out. No such problem on my iPhone5..

    I had the same problem and just solved it. If you have Restrictions Disabled OFF for iBookstore in your settings, that's going to block access to the Store. How to check that?
    Settings -> General -> Restrictions -> iBookstore. If OFF is selected, switch it to ON. Voila! :)
    Note that you might have to enter a passcode if -you created one -once you click on "Restrictions".

  • Why can't i acess the itunes store from my itunes?

    Someone please give me the answer!!!!

    Close your iTunes,
    Go to command Prompt -
    (Win 7/Vista) - START/ALL PROGRAMS/ACCESSORIES, right mouse click "Command Prompt", choose "Run as Administrator".
    (Win XP SP2 &amp; above) - START/ALL PROGRAMS/ACCESSORIES/Command Prompt
    In the "Command Prompt" screen, type in
    netsh winsock reset
    Hit "ENTER" key
    Restart your computer.
    If you do get a prompt after restart windows to remap LSP, just click NO.
    Now launch your iTunes and see if it is working now.
    If you are still having these type of problems after trying the winsock reset, refer to this article to identify which software in your system is inserting LSP:
    iTunes 10.5 for Windows: May see performance issues and blank iTunes Store
    http://support.apple.com/kb/TS4123?viewlocale=en_US

  • Why can't I remove the Genius button from my iPod Touch?

    I decided to remove Genius functionality from my iPod, so I shut it off in iTunes.  However, the button still remains on the now playing screen, and Genius playlist is still listed under my Playlists.  If I attempt to make a Genius playlist for any song though, it says I don't ahve enough similar songs to make one.  How do I completely remove Genius from my device?

    Have you looked at the previous discussions listed on the right side of this page under the heading "More Like This"?

  • Why can I connect to the iTunes store from my ipad

    I'm trying to connect to the app store and it gives me a message saying cant connect

    Try logging out of your account on the iPad by tapping on your id in Settings > Store and then log back in and see if the two stores then work.

Maybe you are looking for

  • Report generation in labview 8 without the toolkit

    HI I have a typical problem. I want to generate report in MS word format. Unfortunately I don't have the toolkit. I am wandering whether there is a method to generate report without using the toolkit or I have to get the toolkit to be able generate r

  • Re: My TEAC DV-w28ECT driver used to read both DVD and CD now it only reads DVD

    My TEAC DV-w28ECT driver used to read both DVD and CD now, it only reads DVDs. what happened and how can I fix it? I have Windows Vista

  • Trouble synching Calendar on i-Pad

    I have found some appointments were missing from my i-Pad calendar.  I therfore tried to re-synch it through i-tunes and got the following message. "iTunes could not synch calendars to the iPad "(its name)" because an error occurred remapping record

  • Audition CS6 Flash Video

    Hi, today I downloaded the Audition CS6 trial. I have used CS5 a while back, but mostly use Ableton these days. However, thought I'd give Audition a whirl. Following a tutorial to try it out, I came to the Video Clip ( Lynda.com - Audition CS6 Essent

  • Partitions on TC - Bootable Drive?

    I had a good set-up wherein I use an external HD partitioned to store my Time Machine backups (Partition #1) and make a bootable copy of my HD (using SuperDuper) on Partition #2. The External HD just died. Before replacing it (I borrowed one to make