简体   繁体   中英

Does method.invoke create a new thread in java?

I am calling a method using reflection in Java using the method.invoke function. Does that method.invoke create a new thread or it will run with the current thread?

No, it does not create a new thread.

The JavaDocs don't mention anything about multithreading or being asynchronous, and this is typically a very strong indication that it will be executed in the current thread.

Constructs that may use other threads are typically quite explicit about not making any guarantees as to which thread will execute the code - see the documentation for Executors or Stream

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM