openvenues / jpostal

Java/JNI bindings to libpostal for for fast international street address parsing/normalization
MIT License
106 stars 44 forks source link

Is JPostal thread-safe? #23

Closed ajdocherty closed 7 years ago

ajdocherty commented 7 years ago

Hello, I wasn't sure how to contact you, so apologies for this strange way of asking you a question via a github issue.

Can you confirm whether JPostal is thread-safe? I.e. If I write a wrapper around the parser, and that wrapper can be used by multiple threads, it will work the same as with one thread?

Many thanks

albarrentine commented 7 years ago

It's perfectly OK to ask questions via issues.

Yes, jpostal is thead-safe (including thread-safe Singletons), so you can use the library from multiple threads, but all the calls to libpostal are synchronized so there's no parallelism. Your application can still use multiple cores if the threads are doing other things in addition to the libpostal calls, but if they're just trying to call libpostal in parallel, they'd be contending for the Singleton's intrinsic lock and the performance would be worse than single-threaded.