What are the main differences between EnhancedPatternLayout and PatternLayout?

Checking the javadoc for PatternLayout, I noticed that using EnhancedPatternLayout is recommended instead. However, it seems to be almost the same.

What are the main differences, especially those that I should know about?

I am also wondering why they made a separate class and not improved the original class. Any syntax differences?

+6
source share
3 answers

Check the documentation , everything is explained. EnhancedPatternLayout - An extended version of PatternLayout . It should be used instead of PatternLayout (except for the reason for compatibility with PatternLayout ).

PatternLayout contains some problems that are missing in EnhancedPatternLayout, especially with synchronization.

+3
source

EnhancedPatternLayout formats the result as a StringBuffer, while PatternLayout formats the result as a string.

0
source

The main difference between PatternLayout and EnhancedPatternLayout is in the format () method. PatternLayout relies on a member field called sbuf , which it modifies, while EnhancedPatternLayout uses a private instance of StringBuffer. This means that calls to PatternLayout.format () are susceptible to data races during simultaneous calls, while simultaneous calls to EnhancedPatternLayout.format () are not.

0
source

Source: https://habr.com/ru/post/909544/


All Articles