quiz icon indicating copy to clipboard operation
quiz copied to clipboard

fix and improvement

Open ail-man opened this issue 10 years ago • 1 comments

  1. use try-with-resources to close Streams finally
  2. it is better to use ReadWriteLock in accessors because to multithreading read property
  3. use StringBuilder (mutable) instead String (immutable) to reduce creating String-objects and improve code performance.

ail-man avatar Feb 02 '16 08:02 ail-man

  1. Use try-with-resources to autoclose Streams finally
  2. Write lock is needed in set() and saveContent() methods. Read lock is needed in get(), getContent() and getContentWithoutUnicode() methods. This will increase performance in multithreaded code reading mode and prevent from reading the field by another thread while writing (preventing from ConcurrentModificationException)
  3. Use StringBuilder (mutable) instead String (immutable) to reduce creating String-objects and improve code performance.
  4. Avoid duplicate code. We can to create one private method getStringContent(boolean withUnicode) and use it in getContent() and getContentWithoutUnicode() methods.
  5. If we can to change the API, we can to use one static method getContent() instead of two non static, because it will eliminate the need to lock the file for reading. Or it is better to move static getContent() method to another FileUtils class. In this case it will be better to rename class Parser to FileHolder.
  6. Minor fixes (unicode symbol constant)

ail-man avatar Feb 10 '16 10:02 ail-man