-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
cause by java.lang.NullPointerException: no decoder for identity number:-153049664 #852
Comments
DecoderMap操作都加锁的,应该不存在并发问题。 如果你自己调用了register,那么就是想定制自己的序列化策略,所以此时initDefaultDecoder不再生效,你应该把自己需要的decoder都注册一下。 |
没有主动调用,用的Kryo5ValueDecoder, -153049664就是Kryo5序列化反序列化的标记。 |
以前没锁但是有synchronized,一样的。没看出这里有并发问题。 |
initDefaultDecoder方法没有锁啊,两个线程可以同时进入initDefaultDecoder方法; |
synchronized代码块怎么会有两个线程同时进去? 就算这里没有加任何线程安全措施,发生并发问题的概率也是极低的。你的问题如果是每次都出现的,应该从别的地方找原因。 |
synchronized代码块不会有两个线程进入,但是initDefaultDecoder方法可以,initDefaultDecoder方法没有加同步控制; |
如果register我自己调用的话就不来这里提问啦,肯定没有调用,谢谢 |
我不明白你的意思,我也没看出来现在的代码有什么问题(除了上面提到的两个问题:用户自己调用register没有注册完全,或者版本问题)。 |
还有你要注意锁里面办完事了才设置inited为true,这是很常见的优化手法,保证正确性的同时优化性能,后续调用这个方法都不必加解锁 |
public synchronized void register(int identityNumber, AbstractValueDecoder decoder) {
DecoderMap类initDefaultDecoder方法没有执行完初始化的时候,调用register就把inited设置成了true(**### 这里说的是initDefaultDecoder方法调用了register不是说用户自己调用**),导致没有初始化完就有其他线程使用报错(A线程调用initDefaultDecoder方法执行到register(SerialPolicy.IDENTITY_NUMBER_JAVA, defaultJavaValueDecoder())的时候,把inited改成了true,此时register(SerialPolicy.IDENTITY_NUMBER_KRYO5, Kryo5ValueDecoder.INSTANCE还没有执行完毕,没有完全初始化;此刻B线程在A进入inited判断为true直接返回,导致只初始化一个defaultJavaValueDecoder的时候返回) |
我知道了,问题是在于register方法 |
cause by java.lang.NullPointerException: no decoder for identity number:-153049664
项目刚启动时有并发读redis缓存会报错,因为DecoderMap类initDefaultDecoder方法没有执行完初始化的时候,调用register就把inited设置成了true,导致没有初始化完就有其他线程使用报错
The text was updated successfully, but these errors were encountered: