Question

My question actually consists of two parts. The first question has to do when using the java Method class to invoke a method from a loaded class. Does this "invoked" method run in a separate thread? If so, can you access it?

Second, consider the case that I call a method from a loaded class using invoke. Assume the method calls System.exit(). If I use a security manager to stop the System.exit() call from happening, and the parent program catches the security manager exception, will the child thread be properly garbage collected?

Était-ce utile?

La solution

Does this "invoked" method run in a separate thread?

No, Java Reflection in general has nothing to do with multithreading.

will the child thread be properly garbage collected?

Since there is no multithreading involved, I believe your second question is rendered moot. More generally, though, there is no propagation of exceptions between threads, so if a child thread ends due to an unhandled exception, the parent thread won't be able to magically "catch" it. Think about it logically: the parent thread will at that point be off to some completely unrelated piece of code and there would be no sense in interrupting it with a stacktrace that has nothing to do with what it is executing.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top