java - Spring bean to compile all the regular expression -


if compiling regular expression time consuming part, idea have spring bean compile regular expression in projects during initialization of bean , make (the compiled regex) available whichever classes require subsequent matching against target string? have never seen thing - of time times, class matching pattern compile @ same time. not rather more time consuming compile each time pattern matching done?

it advisable compile regex once if you're going use multiple times.

regex compilation becomes more expensive more complicated gets, , of time on , on without realising it. case in point, these convenience methods (taken here) go through compilation process under hood:

  • pattern.matches
  • string.matches
  • string.replaceall
  • string.replacefirst
  • string.split

so should keep in mind "convenience" methods you're calling , compile multiple use regex once; either on startup or first time use it.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -