Specifically, I am looking for a pattern to provide components with information about the current run-time specific to the current thread.
Currently, to pass the user who is in charge of the given process to the thread, I set the thread name to the user’s identification number. The components can then get the information about who owns the process through the thread name.
This seems to me like an abuse of thread names. Is there a better way to hold this information?
The Java class
ThreadLocalis the right way to go about this. It will keep information in the thread’s context and you can use it to set the user information at one point, and then access it from the same thread a later point, e.g. from a different layer of your application. This will work as long as the components/services are running in the same thread.