-3

Often I create Child threads within the main() as

Thread thread = new Thread(new Runnable(){public void run(){}});

Likewise, is it also possible to create parent threads ?

Akash
  • 4,956
  • 11
  • 42
  • 70
  • 2
    What do you mean by "to create parent thread"? How could a running Thread spawn it's own creator? Or a child give birth to it's own father? I'm sure you meant something else. – Anthony Accioly Jul 03 '12 at 17:26
  • In general, while the creating thread is often referred to as the "parent" and the created thread as the "child", there isn't usually a semantic relationship between the two. What functionality were you hoping to achieve? – dlev Jul 03 '12 at 17:26
  • like creating a independent thread uncreated to the main() – Akash Jul 03 '12 at 17:28
  • @Akash That just begs the question, though. For what purpose would you like such a thread? How would it be different from a normal thread? – dlev Jul 03 '12 at 17:30
  • ...You _cannot_ start a thread that isn't a descendant of the main thread. Is that clear enough? – Louis Wasserman Jul 03 '12 at 17:35
  • If you're trying to fork the parent process, this might be of use: http://stackoverflow.com/q/287633/487075 – CountMurphy Jul 03 '12 at 17:47

2 Answers2

4

Runtime.exec()?

see: How to create a process in Java

I think we're really not sure what you mean by "parent thread" though...

From coderanch.com: http://www.coderanch.com/t/475322/threads/java/Parent-thread-id

Except for the thread which is created by the JVM to start the application, every thread is created by some other thread. You have decided to call this the "parent thread"; that isn't a concept of the Java language, though.

Community
  • 1
  • 1
0

main() is the parent thread......

Try this....

public static void main(String[] args)
    {

        System.out.println(Thead.currentThead().getName());


    }
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75