同步功能和同步块有什么区别? [英] What is the difference between a synchronized function and synchronized block?

查看:70
本文介绍了同步功能和同步块有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public synchronized void addition()
{
   //something;
}

public void addtion()
{
     synchronized (//something)
     {
        //something;
     }
}

如果我错了,请忽略此问题.

If I am wrong Ignore this question.

推荐答案

第一个,一次只有一个线程可以执行整个方法,而第二个,如果不使用,则只有一个线程可以执行该同步块. 作为参数.

it the first one only one thread can execute whole method at a time whereas in second one only one thread can execute that synchronized block if not used this as parameter.

这里是它的副本使用同步方法而不是同步方法是否有优势阻止吗?

这篇关于同步功能和同步块有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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