K
K
kirawa2017-01-25 15:28:31
Java
kirawa, 2017-01-25 15:28:31

How to synchronize a static method?

log4j has a static method - MDC.put(); Which allows you to write and then pull out any data in the logging template. I have a multi-threaded application and therefore MDC.put(); overwrites data by another thread. Is there any way to synchronize this method??

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
parkito, 2017-01-25
@parkito

Место вызова MDC.put() в synchronize блок.

Дмитрий, 2017-01-29
@dsv

странно, вроде бы не должно переписываться ничего, судя по документации:
put(String key, Object o)
Put a context value (the o parameter) as identified with the key parameter into the current thread's context map.
на каждый поток свой контекст

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question