Hello Jim,
Thread-safety is going to be up to the code in your tasks on the node side, and up to your application code on the client side. If the outside libraries you use are not thread safe, you will need to synhronize their invokcations among tasks, or use some kind of locking mechanism to achieve thread-sfatey. Synchronizing each outside API call individually may not be thread safe either, for instance if the outside library keeps a global state, as with static variables. Thus, your tasks should implement a pattern similar to this:
public class MyTask extends AbtsractTask<String> {
private static final Lock GLOBAL_LOCK = new ReentrantLock();
@Override
public void run() {
// part of the code not using 3rd-party libraries
...
// part of the code that uses 3rd-party libraries
GLOBAL_LOCK.lock();
try {
...
} finally {
GLOBAL_LOCK.unlock();
}
// part of the code not using 3rd-party libraries
...
}
}
Of course, this means that potentially large chunks of the processing time will not be performed in parallel, which will impact the overall performance. Since this locking pattern applies at the individual node level, you could mitigate by having more nodes with less processing threads each. For instance, instead of having 1 node with 4 processing htreads on each machine, you could start 2 nodes with 2 threads each, or 4 nodes with 1 thread (in which case locking is possibly no longer necessary), etc ...
Sincerely,
-Laurent