Call stop () on the stream.
Yes, this is an obsolete method. However, it really should not be "obsolete", it should be "dangerous". However, in some cases there is no choice but to use it, and calling the “agent” provided by the user is one such case.
Make sure your program does not use data that is processed by this user stream; or, if you do, design a transaction mechanism to securely exchange data between threads.
Even this method does not guarantee termination of the flow. For example, a user can catch the received Throwable and ignore it. Or, a thread implementation may not respond to stop() calls if the thread is in some native code. But this is your best chance.
source share