Closing all child threads when closing the stage

I have multiple instances of child threads which are started and should continue to execute in till the applications exits.
I have classes which extends Task and I create the threads as
new Thread(object of the class).start();
when it comes to interrupting/stoping (dont know which one is correct, please let me know) the threads which should be done inside
primaryStage.onCloseOperation(){}
here i want to end all child threads but since my threads are spreaded across different classes, my not having a clear picture how to achieve this.
I know there is some designing problem, in my application, when it comes to threads, but I am not able to figure out how to resolve out.

Use thread.setDaemon(true) Thread (Java Platform SE 7 )
I suggest to use the Executor Framework and a ThreadFactory, to only need to create a daemon thread once.
Something like this:
Executor executor = Executors.newCachedThreadPool(new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setDaemon(true);
                return thread;
And then use it like this:
executor.execute(yourTaskOrRunnable);
When there are only daemon threads running, the JVM will halt and also stop all daemon threads.

Similar Messages

  • I lost all my playlists when downloading the new itunes. Anyway to get them back?

    I lost all my playlists when downloading the new itunes. Besides honestly wanting to cry, is there anyway to get them back without making them all AGAIN? And thanks so much, stupid Apple. Am looking for a new MP3 player to take your stupid ipod player's place. I used to love my ipod...now everytime I turn around, apple has screwed with something that causes ME time and trouble.

    If you created/burned Recovery Media boot from it to restore the original OS with all drivers/software. If you don't have Recovery Media you can order from HP for a small fee. Contact HP Support in your country /region to request Recovery Media. Worldwide contact info can be accessed here>>Contact HP
    ******Clicking the Thumbs-Up button is a way to say -Thanks!.******
    **Click Accept as Solution on a Reply that solves your issue to help others**

  • Waiting the main thread till all child thread has completed

    I am in the process of developing a batch application in Java 5.0 which extensively uses the java.util.concurrency API. Here is a small description of what the batch process will do,
    1. Retrieve values from DB and populate a blocking queue in main thread.
    2. Instantiate a Threadpool by calling, Executors.newFixedThreadPool(2)
    3. Invoking the following block of code from the main thread,
    while(!iBlockingQueue.isEmpty()) {
        AbstractProcessor lProcessor = new  DefaultProcessor((BusinessObject)iBlockingQueue.remove());
        iThreadPool.execute(lProcessor);
    }DefaultProcessor is a class that extends Thread.
    4. Invoking the following block of code from the main thread,
    iThreadPool.shutdown();
    try {
         iThreadPool.awaitTermination(30, TimeUnit.SECONDS);
         } catch (InterruptedException interruptedException) {
              iLogger.debug("Error in await termination...", interruptedException);
    Since, this is the first time I am using the java.util.concurrency API, I want to know whether this is the right way to wait for all the child threads to complete before executing further statements in the main (parent) thread. Or do I necessariliy have to call join() to ensure that the main thread waits for all the child threads to finish which can only happen when the queue is empty.
    Please note here that as per the requirements of the application the blocking queue is filled only once at the very beginning.
    I will appreciate any inputs on this.
    Thanks.

    looks like you would be waiting on a queue twice, once in the loop and again, under the hood, in the threadpool's execute()
    the threadpool's internal queue is all that is needed
    if your iBlockingQueue is also the threadpool's internal queue, you might have a problem when you remove() the BusinessObject
    by making DefaultProcessor extend Thread you are, in effect, implementing your own threadpool without the pooling
    DefaultProcessor need only implement Runnable, it will be wrapped in a thread within the pool and start() called
    to implement a clean shutdown, I suggest writing DefaultProcessor.run() as an infinite loop around the blocking queue poll(timeout) and a stop flag that is checked before going back to poll
    class DefaultProcessor implements Runnable {
      private BlockingQueue myQ;
      private boolean myStopFlag;
      DefaultProcessor( BlockingQueue bq ) { myQ = bq; }
      public void run() {
        BusinessObject bo = null;
        while( !myStopFlag && (bo=myQ.poll( 10, SECONDS )) ) {
          // business code here
      public void stop() { myStopFlag = true; }
    } Now, after iThreadPool.shutdown(), either call stop() on all DefaultProcessors (or alternatively send "poison" messages to the queue), and give yourself enough time to allow processing to finish.

  • Printing all asets that appear on the stage?

    What is the simplest way of print all the various shapes,
    sprites and movieclips that I have dynamically displayed on the
    stage? I know the PrintJob class accepts 1 sprite with its
    PrintJob.addPage() method, but I don't want to create a new sprite
    and all everything to that (and position everything relative to
    eachother) - seems like I'd be duplicating what I do for displaying
    stuff visually. This would also mean every time I want to print the
    entire stage of a project, this code would have to be custom - very
    inefficient.
    So, I think I might be missing something obvious (I hope so).
    Any thoughts?

    After struggling with this issue, I've decided to (currently)
    go with a bitmap solution. You can create a bitmap of the stage and
    100% of its contents with the code below. The downside of this -
    for printing - is that the quality is lower than when printing
    vector artwork. (If anybody has a solution to my issue above,
    please post)

  • When will the stage.stage3Ds[0].transparent property come back?!?

    Hi,
    I had a nice little Augmented Reality App working with the Adobe Flash Player 11 beta. I used the stage.stage3Ds[0].transparent=true; property. But since the Adobe Flash Player 11 RC1 this feature is no longe available. Adobe said that it will come back soon. Does somybody have any news when?
    It is really anoying that I can't use my Application anymore.
    Please Adobe, bring that function back!
    Thanks. Laurid

    we try to keep with a 3 month release cycle for each project.  as for stage3d for mobile, there is work to be done but should be in the pipeline.  no other information about it's schedule is available.  it's pretty thin on specifics, but i hope it gives you a general idea...

  • Acrobat Pro opens all my PDFs when starting the program

    When I try to open Acrobat Pro to read a document, it instantly opens up every PDF on my computer until I force-quit it. I've tried trashing the Adobe Acrobat preferences and rebooting, but the problem persists.
    I'm using a Macintosh with OS 10.5.7. Can anyone please tell me how to fix this? I need to read docs through Acrobat and I can't access them now.
    Thanks.
    Jill

    cree8now wrote:
    Thanks for the suggestion but I've just spent ages trying to get AppleJack to work on my Mac OS X 10.5.7 and nothing happens. I've installed it twice and the application doesn't show up. I rebooted and held down command and s but still nothing. How do I access it? And since it seems to be more of a developer's tool, will I mess things up since I'm not a developer (or even close)?
    Startup  or restart in single user mode. Command(Cloverleaf/Apple) key - S
    wait for B & W Screen wait till all text load and show a Blinking (Block type) Cursor/prompt. at Prompt type AppleJack.
    Follow the directions.
    note 3 & 4 are run once for system, and once for each user account.
    And make sure you downloaded and installed version for OSX.5

  • Why doesn't my E4200 wireless router show all attached devices when viewing the DHCP Client table?

    I recently installed some wireless IP cameras and when attempting to re-install a camera I went into the DHCP Client table to verify which IP a camera was using to set it up, but I could not...and still cannot see any of my cameras in the table even though I can access three of them directly through the IE web browser. I initially power cycled both the E4200 router and Motorola cable modem, and then later just the wireless router...but I still do not see the devices connected. I currently have 2.0.37 firmware even though I was told by Cisco support that there was a later version available, just before being informed that I do not have support available and could purchase it. I attempted to locate a newer version, but the online upgrade portion of the Cisco Connect software searched the net and then states that I have the latest version available. I also opened a Firefox browser to see if maybe my browser was causing issues, but the same limited table appears without all entries available. I even opened the Cisco Connect software on another laptop with the same limited results.
    Other than a factory reset, any suggestions to get me E4200 dual band wireless router to show all attached devices through the DHCP Client table as it previously did approximately two weeks ago? Thanks!

    barrysegal wrote:
    I recently installed some wireless IP cameras and when attempting to re-install a camera I went into the DHCP Client table to verify which IP a camera was using to set it up, but I could not...and still cannot see any of my cameras in the table even though I can access three of them directly through the IE web browser. I initially power cycled both the E4200 router and Motorola cable modem, and then later just the wireless router...but I still do not see the devices connected. I currently have 2.0.37 firmware even though I was told by Cisco support that there was a later version available, just before being informed that I do not have support available and could purchase it. I attempted to locate a newer version, but the online upgrade portion of the Cisco Connect software searched the net and then states that I have the latest version available. I also opened a Firefox browser to see if maybe my browser was causing issues, but the same limited table appears without all entries available. I even opened the Cisco Connect software on another laptop with the same limited results.
    Other than a factory reset, any suggestions to get me E4200 dual band wireless router to show all attached devices through the DHCP Client table as it previously did approximately two weeks ago? Thanks!
    It is strongly recommended that you upgrade the firmware to a smart wifi, which may resolve lot of bugs. You can also download the firmware here:
    E4200v2 Linksys Smart Wi-Fi Firmware11/19/2012
    Ver.2.1.39.145204
    Download
    18.3 MB

  • "Track who downloaded what, when," however Adobe deleted all tracking data when forcing the move from SendNow to Send

    I have transcripts from chats with two different Adobe employees (June 2014 and September 2014) who promised that Adobe had retained the tracking data (not the files). They said that the tracking data would not be available to users at the time of the transition from Send to SendNow, however both promised that eventually the data would be migrated from a SendNow account to the new Send account.
    Adobe sold us all on being able to "Track who downloaded what, when." Were we instead sold a bill of goods?
    Am desperate for an answer.

    See my response to your other posting.

  • My photosmart D110 printer will not print at all wireless or when connected; the printer will copy .

    My D110 Photosmart printer will not print when I want to have something printed from my laptop; I have made sure everything was connected. I have lost the the disk that came with it. Please help the serial# {Removed for privacy}
                                                                       Thank You, Kevin Jackson

    What operating system?  Running the diagnostics at http://www.hp.com/go/tools may help resolve the issue.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • Downloaded Firefox 4.0, followed all directions. When checking the version the icon in the Applications folder to see that the new one is in, it still says that I have the 3.5.18. What am I doing wrong?

    I have a Macbook 2008, Mac OS X, version 10.5.8, processor 2 Ghz Intel Core 2 Duo, Memory 2 GB 1067 MHz DDR3.
    I downloaded Firefox 4.0 as prompted two times on different days and the same thing occurred.

    Firefox 3.6.16 has a newer build and release date than Firefox 4.0 does.

  • 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);

  • Kill all childen threads on close?

    In my jfx2 app I have a thread that gets stood up. When I click the [X] for the main application window I want all "child threads" to be killed. Is this possible? I have not seen anything in the tutorials to describe this nor a way to override a "onClose" like method? Any help would be great.
    Riley

    Use childThread.setDaemon(true) for all child threads:
    (http://www.jguru.com/faq/view.jsp?EID=43724 "What is a daemon thread? When should I use setDaemon() and why?")
    If it is not possible to use a Daemon thread, implement logic in an onHidden event handler to notify the threads that they need to shutdown, implement logic in the threads to handle the shutdown notification, and join to each of the threads to await their completion or use a CountDownLatch. If you do this you might want to do the join or CountDownLatch wait in it's own seperate shutdown thread so as not to block the JavaFX application thread.
    http://docs.oracle.com/javafx/2.0/api/javafx/stage/Window.html#setOnHidden%28javafx.event.EventHandler%29
    http://javahowto.blogspot.com/2007/05/when-to-join-threads.html
    http://javahowto.blogspot.com/2011/08/when-to-join-threads-with.html
    Or, if there would be no adverse consequences, you can just call System.exit as aidreamer suggests.

  • New tweens and resizing the stage: Help!

    Hi all. I'm going nuts trying to figure this out.
    I built an animation project at 630 pixels wide. Turns out the project needs to be 430 pixels wide. In CS3, using the classic tweens, I would simply resize the stage, Onion All, then resize everything on the stage at once. But with the new tween structure, it looks like I can't do a mass resize like that. Anything that's been tweened using the motion editor does not resize.
    I know I can just create a new movie clip, paste all frames into it and then resize the MC, but I have some JPEGs of signatures that pixellate when they are resized that way.
    So, can you onion skin the new tweens? Is there a workaround?
    Thanks!

    I'm afraid there isn't a good answer for this one - it's one of the present limitations that we're aware of. The problem is twofold: One instance per tween instead of two/more (Edit multiple frames is entirely based on multiple instances - a tween only has one), and auto-keyframing (usually making things easier, but for this, complicating things - if you change the scale at a location it automatically tweens the change, which you don't want in this use case).
    For any motion paths, you need to select each and then scale them (you can use the Transform panel to enter a percentage. Mutliple selected motion paths will scale the instances instead (unfortunately for this case).  You can try selecting multiple and using the Transform panel, but this doesn't work well yet.
    If you haven't tweened the scale of your instances and they start at the same position, you're in a bit more luck. Put the playhead at the first frame of the span(s) and then scale the instances. If you have tweened the scale, then you'd need to move the scale tween up/down in the motion editor (press the Alt key while dragging the path in the graph).
    In the even less likely chance the instances share the same tween, I'd do this for one instance, save it as a preset and then apply it to the rest.
    I know this is a pain - I'm sorry it's not better for changing the size of the Stage. We didn't get the time to make Edit Mutliple Frames better for new motion in this release.

  • Initialize QTMovie in a child thread by passing Movie object.

    I'm working on an Qt (Qt framework) application in which I'm making use of a .mm file to call MAC specific functions.
    I need to initialize QTMovie in a child thread by passing Movie object.
    [QTMovie movieWithQuickTimeMovie:movie disposeWhenDone:TRUE error:nil]
    It appears like I have to initialize QTMovie in main thread. I came across performSelectorOnMainThread which might be of some help. Could anyone please show me the right usage of the same?
    I need to call a method using performSelectorOnMainThread by passing the Movie object to it and which returns the initialized QTMovie object.
    Thanks in advance.

    Ah, you seem to be on to something, there. The main thread gives
    sun.misc.Launcher$AppClassLoader@111f71
    while the child thread gives null. The same occurs whether the experiment is in
    the same JVM instance or not.
    So presumably this means I need to get the context loader from the main thread
    and set it in the child thread manually!?
    - Angus.
    Patrick Linskey wrote:
    Angus Monro <[email protected]> writes:
    Okay.... I'm not really sure what you're asking for. What I've done is
    printed the ClassLoader object as given by
    com.solarmetric.util.app.Prefs.class.getClassLoader(), along with its
    parent recursively up the tree of loaders. This gave:
    sun.misc.Launcher$AppClassLoader@111f71
    sun.misc.Launcher$ExtClassLoader@256a7c
    This result was exactly the same irrespective of whether I did it from the
    main thread or the child thread. But the exception still happens only the
    child thread.Sorry, I should have been more clear. Can you print out the current
    thread's context's classloader?
    System.out.println (Thread.currentThread ().getContextClassLoader ());
    Also, what happens if you run the test in the main thread and then in
    the child thread, all in the same JVM?
    -Patrick
    - Angus.
    Patrick Linskey [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • If I cannot "go back" when using a website I cannot close that specific tab and have to close them all. I have had to restart from scratch several times today . Having a choice of closing the last tab only would be very useful. Why can't I?

    After I browsed a page in a websit, I could not close that page by using the X in the rt. hand top corner as when I did this Firefox told me that it would close all tabs. It was the only way out so I closed them and started from scratch.

    mratlasdreamz,
    which app are you running when you get the annoying chime as you try to correct a typo?
    If you’re sure that you have a 2.4 GHz Core 2 Duo CPU and 2 GB of 667 MHz RAM, then what you have is not a MacBook Pro, but an Early 2008 MacBook (did it really cost £2000 then?) — and with that model of MacBook, you could upgrade to Lion. Whether you stay with Snow Leopard or upgrade to Lion, you might find that upgrading your RAM from 2 GB to 4 GB could be helpful.
    You can confirm which model you have by selecting About This Mac on the Apple menu, clicking the “More Info…” button, then clicking on the “System Report…” button, and looking at the “Model Identifier” value in the Hardware Overview section. If you have an Early 2008 MacBook, then the model identifier will say “MacBook4,1”. If it gives a different model identifier, then include that model identifier in your reply, and we can determine which model you have, and which CPU and speed of RAM it uses.
    Note that Firefox 26 still supports Snow Leopard, and that Mozilla makes no CPU recommendations for Firefox on OS X other than “an Intel x86 processor”.

Maybe you are looking for