Results 1 to 7 of 7
  1. #1
    jithan is offline Member
    Join Date
    Jun 2008
    Posts
    39
    Rep Power
    0

    Default dynamic thread handling....

    hello friends,
    i want to do a dynamic thread handling. i want to start and stop threads in dynamically. for example if i send an argument 5 it has to start 5 threads and it has to run for particular period of time and it has to automatically destroy when the time has to reach...... how to solve....... pls help me. its very urgent.....

    Thanks in advance...

  2. #2
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    Default

    Can you narrow your question somehow ? Now it sounds as a very common one and should be solved by reading Thread class documentation.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    t has to automatically destroy when the time has to reach..
    The recommended way to stop a thread is for the thread itself to recognize the need to end and to exit. This would require that the thread be testing a flag to see if it is to exit.
    The stop method is deprecatd and not recommended.

  4. #4
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    Default

    I'd say that testing flag is not quite modern technique. Usage of methods like Thread.sleep() or Object.wait() seems more preferable. If thread was interrupted exception is thrown.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    Sorry, don't see how using sleep in an thread that is doing something in a loop will necessarily react to an interrupt if the code is not in sleep when the interrupt is sent. Wouldn't the thread have to test to see if it was interrtupted? And if it never does a wait???

  6. #6
    somesh2011 is offline Member
    Join Date
    Aug 2008
    Posts
    1
    Rep Power
    0

    Default

    Quote Originally Posted by jithan View Post
    hello friends,
    i want to do a dynamic thread handling. i want to start and stop threads in dynamically. for example if i send an argument 5 it has to start 5 threads and it has to run for particular period of time and it has to automatically destroy when the time has to reach...... how to solve....... pls help me. its very urgent.....

    Thanks in advance...
    reply:

    use while loop condtional by time function format.ok

  7. #7
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Sorry, don't see how using sleep in an thread that is doing something in a loop will necessarily react to an interrupt if the code is not in sleep when the interrupt is sent.
    Java Code:
        public static class MyThread extends Thread{
            @Override
            public void run() {
                interrupt();
                try{
                    Thread.sleep(10);
                    System.out.println("Bye");
                }catch(Throwable t){
                   System.out.println(t);
                }
                
            }
        }
    gives
    java.lang.InterruptedException: sleep interrupted
    output

Similar Threads

  1. passing a value from parent thread to child thread
    By sachinj13 in forum Threads and Synchronization
    Replies: 7
    Last Post: 09-07-2008, 09:06 PM
  2. data from the main/GUI thread to another runnin thread...
    By cornercuttin in forum Threads and Synchronization
    Replies: 2
    Last Post: 04-23-2008, 10:30 PM
  3. Replies: 0
    Last Post: 01-28-2008, 07:02 AM
  4. how to generate dynamic pdf
    By valery in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 10:01 PM

Posting Permissions

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