同步的Vs信号量 [英] Synchronized Vs Semaphore

查看:194
本文介绍了同步的Vs信号量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读Java中的并发性时,我有以下疑问:

While reading concurrency in Java, I have following doubts:


  1. Java是否提供了较低级别的构造,然后同步进行同步?

  1. Does Java provides lower level construct then synchronized for synchronization?

在什么情况下我们会使用信号量而不是synchronized(在Java中提供监控行为)

In what circumstances will we use semaphore over synchronized (which provides monitor behaviour in Java)


推荐答案

同步只允许一个执行线程同时访问资源。信号量允许最多 n (您可以选择n)执行线程同时访问资源。

Synchronized allows only one thread of execution to access the resource at the same time. Semaphore allows up to n (you get to choose n) threads of execution to access the resource at the same time.

这篇关于同步的Vs信号量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆