Java – prevents the use of non thread safe methods in a multithreaded context
•
Java
Is there any way to throw an exception when a user tries to use a class's non thread safe method in a multithreaded context? I think the main problem is to detect that multiple threads are trying to use this method Or can I use the "not_synchronous" keyword / tag in the function declaration?
Solution
There is no easy way to do this, No If you detect that multiple threads are using a method, you may have to use thread safe collections, etc If you are doing all this, you may have to make the method itself thread safe
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码