Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add thread safety testing and add synchronized for thread safety #42

Merged
merged 1 commit into from
Jan 11, 2021

Conversation

SamYuan1990
Copy link
Member

Signed-off-by: SamYuan1990 yy19902439@126.com

Signed-off-by: SamYuan1990 <yy19902439@126.com>
@SamYuan1990 SamYuan1990 requested review from xiaohui249 and davidkhala and removed request for xiaohui249 January 10, 2021 10:07
Copy link
Member

@davidkhala davidkhala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davidkhala davidkhala merged commit e207700 into Hyperledger-TWGC:master Jan 11, 2021
@SamYuan1990 SamYuan1990 deleted the threadSafety branch January 11, 2021 15:10
IvParameterSpec ivParameterSpec = null;
if (iv != null) {
ivParameterSpec = new IvParameterSpec(iv);
synchronized (this) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看了这段同步代码,以及SM4Util的公开构造方法。我的想法:1、改成synchronized,目的应该是避免一个SM4Util单实例使用出现线程安全问题,但是影响了性能,而且并没有从实质上解决线程安全问题,线程安全问题是由Cipher引起的,而Cipher对象是公用的;2、SM4Util的构造方法是public的,所以从这个层面来讲,上一步的synchronized意义不大,而且实例化SM4Util时,Cipher.getInstance仍然要执行一遍。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦?但是奇怪的是我们的并发测试貌似通过了。@xiaohui249, 建议提交个pr我们看下区别。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants