Initializing two threads with the same instance of a runnable

It’s absolutely fine to do it so long as the code you’re running is designed to support that. Not only will it save some memory by having a single instance instead of multiple instances, but if those threads are trying to communicate via shared data, then it may be absolutely required!

Admittedly communicating via shared state is where threading often gets tricky, so this needs to be done carefully, but from the point of view of the threading system itself, there’s absolutely no problem in having two threads call the run method of a single Runnable instance.

Leave a Comment