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

请问 #272

Closed
jeyhan opened this issue Aug 17, 2016 · 2 comments
Closed

请问 #272

jeyhan opened this issue Aug 17, 2016 · 2 comments
Labels

Comments

@jeyhan
Copy link

jeyhan commented Aug 17, 2016

No description provided.

@Jacksgong
Copy link
Collaborator

是的。这里是对相同内容的String进行同步。

/**
 * Returns an interned string equal to this string. The VM maintains an internal set of
 * unique strings. All string literals found in loaded classes'
 * constant pools are automatically interned. Manually-interned strings are only weakly
 * referenced, so calling {@code intern} won't lead to unwanted retention.
 *
 * <p>Interning is typically used because it guarantees that for interned strings
 * {@code a} and {@code b}, {@code a.equals(b)} can be simplified to
 * {@code a == b}. (This is not true of non-interned strings.)
 *
 * <p>Many applications find it simpler and more convenient to use an explicit
 * {@link java.util.HashMap} to implement their own pools.
 */
public native String intern();

@Jacksgong
Copy link
Collaborator

通常如果是成员变量作为锁的话,确实跑一些inspection的时候,会有这样的提示,目的就是防止由于变量发生改变导致同一个变量,但是由于指向不同的对象,导致锁作用在不同的对象上。

这里使用 eventId.intern() 就是保证了无论是哪个eventId,只要是同样的内容,就是对同一个对象进行加锁。这里并没有对什么作为拓展,就是完成: 对相同eventId的事件进行加锁。

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

No branches or pull requests

2 participants