Results 1 to 4 of 4
  1. #1
    prashanthn is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Main Thread not waiting for grand child thread to finish

    Hi,

    I'm facing some issue with the respected title.
    In my program,
    1. i will start main program, then i need to start a server.
    2. Then i am starting 8 threads, which continuously checks the server performance.
    3. But these child threads are in-turn creating some more child threads.
    4. I have used join for child threads, so that main thread is waiting for child thread to finish, but not waiting for grand child thread to finish.
    5. If i use 2 joins its going into a infinite loop.
    6. I want to run each thread for specific amount of time.
    6. can any one please help into this issue.





    class DnsQueryThread1 extends Thread
    {
    GatewayQueryContext gwcontext;
    //* Initialing variables

    //* constructor declaration

    public void run()
    {
    System.out.println("vikas inside run");
    while(!flag)
    {
    runTest();
    try {
    Thread.sleep(100);
    //Thread.currentThread().join();
    } catch (InterruptedException e) {
    e.printStackTrace();
    }

    long currentTime = System.currentTimeMillis();

    if(currentTime >= (millistoRun + 30000)) { // 1 min = 60 sec = 60000 ms

    flag = true;
    System.out.println("state of thread is" + Thread.currentThread().getState()+ "for count"+tcount);

    }
    }

    }
    public void runTest()
    {
    if(gwcontext != null)
    {
    try {
    sent = sent+1;
    sending queries to server

    }
    catch(Exception e)
    {
    System.out.println("exception caught");
    }
    //this.notify();
    }
    else
    {
    //***************
    }
    }

    }


    public class DnsThreadExmple
    {
    public static void main(String args[]) throws Exception
    {
    /* Initialising values to all the 8 threads
    variablesDeclare();

    Thread1 [] thrdPool = new Thread1[8];
    for (i=0 ; i<8 ; i++) {
    thrdPool[i] = new Thread1();
    thrdPool[i].start();
    }
    for (i=0;i<8;i++)
    thrdPool[i].join();
    //** i want to stop my server here
    }
    public static void variablesDeclare( ) throws Exception
    {
    //* Declaiting of variables and starting my Server;
    }

    }

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    At a glance, that first class isn't even compilable. The variables millisToRun and tcount aren't defined anywhere. And you have what looks like part of a comment floating around inside a method body.

    Post your actual code, and post it inside code tags.
    Get in the habit of using standard Java naming conventions!

  3. #3
    prashanthn is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default

    Hi, its working fine.., As there some concerns we cannot able to display the whole code. But as i explained that main thread is coming out of execution, when the grand child's are under execution. Since we used join for child threads, so main thread is waiting. But child threads are not waiting for grand child threads. if we use join here its going into infinite loop. Can you suggest some solution to solve this..

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    What you're describing doesn't make sense, and we can't help you debug it without seeing the code.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Thread not waiting for another with join()
    By DaCapitalist in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-25-2011, 06:02 PM
  2. Question about 'main thread' and the thread it creates
    By ggyyree in forum Threads and Synchronization
    Replies: 11
    Last Post: 12-10-2010, 07:33 PM
  3. Trigger main thread method from secondary thread?
    By DigitalMan in forum Threads and Synchronization
    Replies: 8
    Last Post: 01-26-2010, 02:13 AM
  4. 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
  5. 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

Posting Permissions

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