可以将同步视为 AOP 中的一个方面吗 [英] Can synchronization be treated as an aspect in AOP

查看:28
本文介绍了可以将同步视为 AOP 中的一个方面吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 AOP 中,任何横切关注点(例如日志记录、事务等)都可以被视为一个方面,并且大多数 AOP 框架都很好地支持这些横切关注点.

I understand that in AOP any cross cutting concerns such as Logging, transaction etc can be treated as an aspect and most of the AOP frameworks very well support these kind of cross-cutting concerns.

我的问题是,

  • 可以将同步视为横切关注点吗?
  • 如果是,是否有任何现成的支持此功能的库(包括 AspectJ 和 Spring AOP)?

我进行了搜索,但找不到很多示例.我遇到了一些受限制的研究论文(1,2).

I searched but could not find many examples. I came across some restricted research papers (1,2) though.

推荐答案

理论上,可以有一个 AOP 框架,为一组方法/类添加同步.实施起来也不难.但这通常不是您想要的.太多的同步和太少的同步一样糟糕,因为您要么陷入死锁,要么将线程顺序化得太多,以至于您无法有效地使用多个内核.

In theory it's possible to have an AOP framework which adds synchronization to a set of methods/classes. It's not even hard to implement. But it is usually not what you want. Too much synchronization is just as bad as too few synchronization, because you either run into deadlocks or you sequentialize your threading so much, that you are not able to use multiple cores effectively.

恐怕没有毫无疑问多线程编程的捷径.

I am afraid there is no no brainer shortcut to multithreaded programming.

这篇关于可以将同步视为 AOP 中的一个方面吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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