Closed marcelomalcher closed 9 years ago
I find very strange that concurrent executions of this static block would happen; class initialization shouldn't allow that (unless you have separate classloaders loading the same class...). Do you have stack trace that shows this? And even concurrent loads of the same resource should not cause any problems, they would just create different InputStream
s that can read the same thing independently.
Yes, it is strange. I think that the static block is initialized only once per classload. I am not sure what was happening, perhaps multiple class loaders loading the class in the same time?
I am trying to find the stack trace regarding this problem in in my log files, but it will be a hard task. I know that an exception with the mapper text file was happening and an ExceptionInInitializerError
was raised in the first time. Then, all the subsequent calls to the AdCategoryMapper
were raising a NoClassDefFoundError
.
I will try to find the stack trace and post here. If I do not find I intend to close this issue.
Closing the issue. I couldn't find the stack trace with the error.
Hey @opinali,
As I said before, thanks for developing and maintaining this awesome libs.
Well, while working with
DoubleClickOpenRtbMapper
I faced the following situation after getting an instance of this class.AdCategoryMapper
which provides a series of methods to convert categories between both specs (DoubleClick and OpenRtb)AdCategoryMapper
has a static block that will be executed in the moment it is loaded by JVM (when it is first referenced in code)So, the issue happens due to the number of concurrent calls to
DoubleClickOpenRtbMapper
(after all, it is RTB, right?). Then, as receiving multiple requests, the JVM fails to execute the static block once, and ends executing more than one time concurrently. As there's only one file, this second (or third, forth...) fails to access the mapping text file (as it is open by another thread) and aExceptionInInitializerError
is thrown. Thus, several subsequent calls toAdCategoryMapper
methods end with aNoClassDefFoundError
exception.I solved this by forcing the load of the
AdCategoryMapper
during the init of my system:This way, when when
DoubleClickOpenRtbMapper
started to receive requests to convert and used theAdCategoryMapper
static methods, it already had the static block executed and had the mapped categories in its static attributes.I thought about opening a PR with some method like
initMappers()
in the constructor ofDoubleClickOpenRtbMapper
to force the loading of mappers likeAdCategoryMapper
.What do you think?