-1

I am new to multi-threading. Recently in an interview I was asked this question. "How to notify parent thread if child thread throw an exception?" I assume parent thread refers to Main Thread. It will be helpful anyone explain this to me through a simple java program?

1 Answers1

0

The answer is non-trivial; the fact that there is a parent/child relationship between the threads is itself misleading. Threads don't as a rule care or get any special relationship with the thread that spawned it at all.

Thus, the answer is a mix of: "Parent/Child? I'm not sure those are appropriate terms to apply to the concept of 'a thread that is going to spawn another thread' and 'the thread that it spawned'", and "the same way any two threads communicate with each other: Carefully, probably via things in the java.util.concurrent package, and really optimally threads should never communicate except through communication channels with built in transactional support, such as a database, or message queue libraries like rabbitMQ.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72