I would like to multi-thread an application, however one library i'm using is not multi-thread capable (i don't know what's the right word ? synchronized ?).
What are my options ?
As far as i know there's nothing in between threads and processes (Runtime.exec) in java (no abstraction in the jvm to have something like an isolated "java process").
How would you deal with that ?
EDIT
Thanks for all the answer, once again, one level of indirection does the trick.
You can ensure that the library in question is used only from a single thread at a time. If it contains instantiatable classes, one possibility is to hold these in thread local storage.
Or you can build a thread-safe wrapper around it.
These approaches could also be combined, e.g. you can wrap the library in a class (it would be a Facade in this case), which is not thread safe in itself, but whose instances you access from a single thread at a time.
Update: as @Wim pointed out, if the library manages global state, you must have a thread safe wrapper to ensure that changes are made visible between threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With