So I have this 3rd party java library I am using and in the documentation it says, not thread safe.
However I just ran it in a separate thread from my UI and it ran fine as expected (otherwise the entire app locks up until everything is finished).
So what can I expect now that I am running a non thread safe library in a thread?
update:
could I run each separate threads for each new class instances of this 3rd party library? or does this mean that I can’t just use more than one thread per class.
Run in thread 1 : ThirdPartyProcessing tpp1 = new ThirdPartyProcessing();
Run in thread 2 : ThirdPartyProcessing tpp2 = new ThirdPartyProcessing();
Run in thread 3 : ThirdPartyProcessing tpp3 = new ThirdPartyProcessing();
Non-thread safe means that the code does not expect to be called from more than one thread simultaneously. If it is called from two (or more) threads at the same time it will not behave as expected.
In your case you’re running it from a single thread, which is fine. It is just no the main thread of the app. No problem with that.
Update
There’s no definite answer, but usually (non) thread-safety is on an instance-by-instance basis. That is: non-thread safe code does not work well only when two threads access the same instance. Therefore, one thread per instance, as you suggest, will probably work fine.
The only caveat is that sometime libraries maintain some of their mutable state in static fields which can lead to to inter-thread collision even if each thread accesses a dedicated instance. However, in most libraries this is not the case.