- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Possible Duplicate:
synchronized block vs synchronized method?
大家好,我想知道 Snippet-A 是否只是 Snippet-B 的语法糖? :
片段A:
public synchronized void F() {
//..code
}
片段B:
public void F() {
synchronized (this) {
//..code
}
}
或者更确切地说,上面两段代码到底有什么区别?
最佳答案
两者是相同的。请参阅§8.4.3.6 Java Language Specification的(JLS):
A
synchronized
method acquires a monitor before it executes. [...] For an instance method, the monitor associated withthis
(the object for which the method was invoked) is used.
在 JLS 的示例中,如下:
synchronized void bump() { count++; }
据说具有与此相同的效果:
void bump() {
synchronized (this) {
count++;
}
}
并且您的两个 F
方法与示例 bump
方法非常相似。
关于java - java中的synchronized关键字仅仅是语法糖吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8375880/
对于NumericVector ,我可以将一个较小的 NumericVector 进行子集化通过使用 IntegerVector包含要子集化的位置。 例如假设x<-c(1,2,2,3,4,5) , i
我的 javascript 文件以配置开始... require.config({ baseUrl: 'scripts', paths: { 'code-mirror'
我的应用程序应该可以使用插件或通常称为糖的方式进行扩展。我会将它们放在 appname.app/Contents/sugars/sugarname.appnamesugar 下 这些是 bundle
我一直在尝试使用 Rcpp 在 C++ 中获取 vector 的等级。我使用了其他糖功能,例如 is_na(); C++中rank R函数有没有类似的糖函数。 Rcpp/ 中是否还有任何可用的 R 糖
我通过 Android Studio 使用 Sugar ORM 进行 Android 开发。 但我想我有一个非常相似的问题。如何将一个/多个结果查询显示为字符串或整数?我的实体看起来像这样: publ
入门读物: Prototypes as "classes" OO JS 按照上述模式,我创建如下库/API var Proto = { constructor: function () {
我在应用程序的第一个版本中使用了 SugarORM。现在,我正在开发第二个版本,它向数据库中添加了新表。 根据 SugarORM documentation “Sugar 会自动为新实体创建表,因此您
我是一名优秀的程序员,十分优秀!