Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
MibLoader not working in multi threaded environments #21
The MibLoader.MibSource class uses a static reference to the ASN.1 parser:
This means that two threads using the MibLoader simultaneously will use the same stateful parser object with the result that both parsings fail with unpredictive results.
Some ways to fix the issue:
There are more reasons than this for not loading MIB files in parallell from several threads. In fact, the javadoc even says so:
I strongly recommend synchronizing all access to the MibLoader if possible.
Being not-thread safe is one thing. Using static stateful objects so that not even two different MibLoader objects can operate in parallell is another. Using a static parser would perhaps make sense if the MibLoader was a singleton object, but it is not. It's not possible to tell from the API that you cannot even have two different MibLoader objects and use them from different threads.
The way I worked around the problem was to use a Proxy object that uses synchronization on a singleton monitor object for all load-methods. This feels like something that should be handled by the library instead of the application code.