本文介绍了在apotentially multithreaded环境中使用静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 在我的项目中,我已经将一些辅助方法静态化了。据我所知 它,这将产生多个线程可以同时访问 静态方法并相互干扰的问题。 我的问题是,对于每个静态方法,我是否需要一次只锁定一个 的访问权限?我注意到微软数据应用程序块也是使用静态方法进行数据访问调用 - 例如执行和 executeNonQuery等。这些方法是否应该只改为允许在任何特定时刻通过 a单线程访问? 也许有一个比这更简单的解决方案。我的一个同事是b b b b that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that that 问题。 任何有关做什么的建议都会非常感激。 谢谢大家 西蒙 解决方案 Hi all,In my project I have made a number of helper methods static. As I understandit, this will create the problem that multiple threads could access thestatic method at the same time and interfere with one another.My question is, for each static method, do I need to lock access to only onecall at a time? I''ve noticed that Microsofts Data Application block alsouses static methods for its data access calls - for example execute andexecuteNonQuery etc. Should these methods be changed to only allow access bya single thread at any given moment?Perhaps there is an easier solution than this. A colleague of mine isbanging on about what a terrible performance hit this will cause but giventhat the application is quite small I dont think that it will be much of aproblem.Any suggestions on what to do would be very much appreciated.Thank you allSimon 解决方案 这篇关于在apotentially multithreaded环境中使用静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 23:43
查看更多