在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(); // ... } }
我有一些关于这种情况的具体问题:
- 覆盖的方法是否会被隐式同步?
- 如果没有,
super
同步会同步吗?- 如果没有
super
叫声,会同步吗?- 有没有办法强制重写方法来使用
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:
- Will the overridden method be implicitly synchronized as well?
- If not, will the
super
-call be synchronized?- If there is no
super
-call, will anything be synchronized?- 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
最满意答案
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
(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 Notifier?(Hudson Notifier?)[2022-08-26]
我认为这是迄今为止最好的通知者。 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通知?(TeamCity Twitter Notifier?)[2024-01-27]
我看到这篇文章,并认为我会给你写一个插件。 这里是关于如何去做的博客文章 这里是谷歌代码项目 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 restore)[2022-08-16]
似乎“配置新的TeamCity安装以使用正确的TeamCity数据目录和数据库”(从这里 )是您的案例的关键。 Seems "configure new TeamCity installation to use proper TeamCity Data Directory and database" (from here) is a key to your case. -
PartCover与TeamCity(PartCover with TeamCity)[2022-01-30]
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) ...
-
Teamcity开始很慢(Teamcity start very slow)[2022-12-13]
我遇到了同样的问题,并且能够在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 ... -
TeamCity电子邮件通知(TeamCity email notification)[2024-01-06]
通过将带有服务消息的行打印到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 ...