How to I could set 'attributes
' to current Thread
in Java, I want to set key-values and get the value in another place, but in the same Thread. like to this http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/MDC.html
In the run() method, we use the currentThread(). getName() method to get the name of the current thread that has invoked the run() method. We use the currentThread(). getId() method to get the id of the current thread that has invoked the run() method.
Thread attributes provide a mechanism for fine-tuning the behavior of individual threads. You may create and customize a thread attribute object to specify other values for the attributes. To specify customized thread attributes, you must follow these steps; Create a pthread_attr_t object.
I do not think you can add attributes to any given thread in Java, but you could use a ThreadLocal
instance to store any special information per thread.
http://download.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html
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