Does Pattern.compile cache?

前端 未结 5 634
盖世英雄少女心
盖世英雄少女心 2020-12-04 01:54

It is likely an implementation detail, but for the Oracle and IBM JDKs at least is the compiled pattern cached or do we as application developers need to perform the caching

5条回答
  •  死守一世寂寞
    2020-12-04 02:17

    As far as I know from looking at the code (JDK 6) it doesn't do caching but once constructed, Pattern object could be cached on application side and shared among multiple threads. Standard pattern seems to be to assign it to final static variable:

    private static final Pattern p = Pattern.compile(",");
    

提交回复
热议问题