首页 \ 问答 \ 在Java中覆盖synchronized方法(Overriding synchronized methods in Java)

在Java中覆盖synchronized方法(Overriding synchronized methods in Java)

假设我有一个类的同步方法:

abstract class Foo {
    public synchronized void foo() {  // synchronized!
        // ...
    };
}

不用使用synchronized修饰符来覆盖它:

class Bar extends Foo {
    @Override
    public void foo() {               // NOT synchronized!
        super.foo();
        // ...
    }
 }

我有一些关于这种情况的具体问题:

  1. 覆盖的方法是否会被隐式同步?
  2. 如果没有, super同步会同步吗?
  3. 如果没有super叫声,会同步吗?
  4. 有没有办法强制重写方法来使用synchronized (我注意到接口中的抽象方法定义或方法定义不允许synchronized关键字)?

Let's say I have a synchronized method on some class:

abstract class Foo {
    public synchronized void foo() {  // synchronized!
        // ...
    };
}

and I overrode it without using the synchronized modifier:

class Bar extends Foo {
    @Override
    public void foo() {               // NOT synchronized!
        super.foo();
        // ...
    }
 }

I have a couple of specific question regarding this scenario:

  1. Will the overridden method be implicitly synchronized as well?
  2. If not, will the super-call be synchronized?
  3. If there is no super-call, will anything be synchronized?
  4. Is there a way to force an overriding method to use synchronized (I noticed that abstract method definitions or method definitions inside an interface don't allow the synchronized keyword)?

原文:https://stackoverflow.com/questions/15374521
更新时间:2023-02-15 07:02

最满意答案

我看到这篇文章,并认为我会给你写一个插件。

这里是关于如何去做的博客文章

这里是谷歌代码项目

TeamCity的- Twitter的通知

替代文字


I saw this post and thought I'd write you a plugin.

here's the blog post on how to do it

and here's the google code project

teamcity-twitter-notifier

alt text
(source: sleepoverrated.com)

相关问答

更多
  • 好的...我得到这个开始在我的Windows服务器上工作。 以下是我配置TeamCity 4.5 Professional的步骤: 下载了JetBrains Git VCS插件 将下载的zip文件复制到.BuildServer\plugins 在Administration> Edit Build Configuration> Edit VCS Root配置屏幕中,我选择了“Git(JetBrains)” 从GitHub项目页面输入我的Clone Url 设置认证方法“默认私钥” - 这是重要的 TeamC ...
  • 我认为这是迄今为止最好的通知者。 Hudson Tray Tracker: http : //code.google.com/p/hudson-tray-tracker/ I think this is the best notifier so far. Hudson Tray Tracker: http://code.google.com/p/hudson-tray-tracker/
  • 我看到这篇文章,并认为我会给你写一个插件。 这里是关于如何去做的博客文章 这里是谷歌代码项目 TeamCity的- Twitter的通知 I saw this post and thought I'd write you a plugin. here's the blog post on how to do it and here's the google code project teamcity-twitter-notifier (source: sleepoverrated.com)
  • 似乎“配置新的TeamCity安装以使用正确的TeamCity数据目录和数据库”(从这里 )是您的案例的关键。 Seems "configure new TeamCity installation to use proper TeamCity Data Directory and database" (from here) is a key to your case.
  • 1)PartCover仅支持32位进程,因此您需要确保您的测试运行器也运行32位。 2)确保使用regsvr32注册PartCover DLL(如果使用服务帐户运行团队城市,则不能使用每用户注册)。 1) PartCover only supports 32 bit processes, so you need to make sure your test runner is also running 32 bit. 2) Make sure you register the PartCover dll u ...
  • TeamCity在其Open API中提供AuthorizationInterceptor接口,您可以将其插入到插件代码中,从而允许您控制授权要求。 shamelessPlug这是我在编写tcMonitor状态页面时使用的。 / shamelessPlug 以下是有关如何使用它的示例代码: /* Add the objects into the constructor and spring will make them available for you */ public ...
  • 我在TeamCity 7.1中使用以下设置来设置Jabber: http://i48.tinypic.com/9ay0xz.png 显然,将my_user@gmail.com替换为应发送通知的Google Talk用户。 请注意,使用Google Talk时,您无法向自己发送消息,因此,对于想要接收通知的用户,服务器用户必须与Jabber帐户不同。 现在,您需要为您的用户配置通知规则。 点击右上角的名称,然后在“我的设置和工具”中点击“监视构建和通知”下的Jabber通知器旁边的“编辑”。 此页面如下所示: ...
  • 我看到使用ClearCase和TeamCity的唯一设置是使用由我的同事Gilles Philippart开发的TCC(TeamCity ClearCase插件): TCC GitHub repo :如最近的提交所示 ,它基于快照视图。 我没有很多关于设置的细节,但它适用于TeamCity6.x 。 The only setup I saw working with ClearCase and TeamCity is by using the TCC (TeamCity ClearCase plugin) ...
  • 我遇到了同样的问题,并且能够在JetBrains工作人员的帮助下解决它。 在启动期间,teamcity需要访问/dev/random作为RNG,并且默认的/dev/random不具有足够的熵来满足该需求。 这阻止了启动过程,直到再次收集到足够的熵。 解决方案是安装havaged守护进程以充分满足熵。 请参阅https://youtrack.jetbrains.com/issue/TW-41035进行原始讨论。 I've had the same problem and was able to solve i ...
  • 通过将带有服务消息的行打印到stdout,将数字添加到构建状态文本: ##teamcity[buildStatus text='Fortify: ; {build.status.text}'] 这样,结果将立即显示在构建列表和构建通知中。 Add the number to the build status text by printing a line with the service message into stdout: ##teamcity[buildStatus text='F ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。