| Author |
Pattern.compile and performance
|
jeroen dijkmeijer
Ranch Hand
Joined: Sep 26, 2003
Posts: 131
|
|
Hi all, I'm doing some string checking on various different columns in lines. A lot of these columns may have only alphanumeric characters with a min/max width of n. Question: Is Pattern.compile internally caching its generated Patterns by some sort of FlyByWeight pattern or should I store them myself in a Map? thanks in advance and regards, Jeroen.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
You should store them yourself -- unless, of course, the possibility of one being reused is not large enough to warrant the space.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
For what it's worth though, the Scanner class (JDK 5+) does cache the patterns it uses. Also, bear in mind that there's an excellent chance that the time required to create and GC these Patterns may be insignificant relative to other things in your code. So like most performance concerns, it's probably best to not spend much time on it unless or until you've got an observable performance problem.
|
"I'm not back." - Bill Harding, Twister
|
 |
jeroen dijkmeijer
Ranch Hand
Joined: Sep 26, 2003
Posts: 131
|
|
Once again thank you for your adequate and quick responses. Very helpful! Jeroen.
|
 |
 |
|
|
subject: Pattern.compile and performance
|
|
|