同步(对象) { } 问题

发布于 2024-08-16 21:11:22 字数 258 浏览 0 评论 0原文

我遇到了一个性能问题,880 个线程同时执行 synchronized() { method() } ,这导致了一个主要的性能问题。

synchronized() 处等待的线程是否可能存在某种限制?哪里可以得到限额?

另一个问题是什么最好放入 synchronized( ? ) 中。因为我有不同的类访问该变量,所以我不能放置synchronized(this)

I have ran into a perfomance problem where 880 threads are doing synchronized() { method() } in the same time and this has lead to a major perfomance problem.

Is it possible that there is some limit of threads waiting at synchronized()? Where can I get the limit?

Another question is what is best to put into synchronized( ? ). Because I have different classes accessing that variable, so I can not put synchronized(this).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑脸一如从前 2024-08-23 21:11:22

无法使用同步来限制任何内容,对于高级并发构造,您需要查看 http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/package-summary.html

关于您在synchronized(?)中放入的内容,这意味着您锁定的内容,这取决于您想要实现的锁定行为。如果您有一个可以从所有不同类访问的全局变量(例如 public static Object LOCK = new Object();),并且您对其进行同步,那么所有类都将锁定该全局变量。

请查看有关同步的 Java 教程

There is no way to limit anything with synchronized, for advanced concurrency constructs you need to have a look at http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/package-summary.html.

Regarding what you put inside synchronized(?), which means on what you lock on, it depends on the locking behavior you want to achieve. If you have a global (for example public static Object LOCK = new Object();) which is accessible from all different classes, and you synchronize on that, then all classes will be locking on that one.

Have a look at the java tutorial on synchronization.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文