Results 1 to 2 of 2
  1. #1
    JohnnyG is offline Member
    Join Date
    Jul 2014
    Posts
    1
    Rep Power
    0

    Default determing when a JAVA thread is finished

    hi all,

    I have been new to JAVA programming language and have been using it for generation of a GUI (with NET BEANS).

    My problem is, when i start a thread within GUI, that takes some amount of time to get finished (around 5min to 20min cpu time),
    i need an a way to detect when the thread is done and accordingly some action to be taken afterwards.
    I tried with isAlive, but to no avail.
    Example is, I press an JButton, thread starts, when finished Jbutton get colour changed.

    Any ideas ???
    Sorry for my english.

    Johnny

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: determing when a JAVA thread is finished

    Interesting that you are new to Java and are already programming a GUI and using threads. You may
    have a difficult time of it since thread programming especially is fraught with dangers.

    5 min to 20 min of CPU time is a whole lot of time (did you mean real time?). In any event, you could
    pass the button instance to the some class that extends Runnable. There should be some way within
    that class to determine when you exit or when the run method returns. Just before that happens, change
    the color of the button.

    Note, if the run method returns from a variety of places, then you could have the run() method call a private
    myRun method. Then all the work is done in myRun. When that method returns, change the color of the
    button in the run() method before returning from the thread. There may be better ways within the concurrent
    packages within the JDK. There may be some concurrency classes that collect or monitor threads for this
    purpose. I recommend you read through those classes to see what they offer.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 1
    Last Post: 01-23-2013, 09:47 AM
  2. Determing class path for jar html embed
    By two7s_clash in forum Java Applets
    Replies: 0
    Last Post: 03-08-2011, 04:11 PM
  3. Problem with determing mouse position!!!
    By G.rocks in forum New To Java
    Replies: 6
    Last Post: 07-15-2010, 06:09 PM
  4. Self determing the server
    By etherkye in forum Networking
    Replies: 4
    Last Post: 06-26-2009, 12:36 AM
  5. Help determing NamingEnumeration type/cast
    By BlankMan in forum Eclipse
    Replies: 1
    Last Post: 09-05-2008, 08:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •