JDK-5018964 : BufferedWriter.lineSeparator member should be private static
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.2
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-03-23
  • Updated: 2004-03-24
  • Resolved: 2004-03-24
Related Reports
Duplicate :  
Description

Name: jl125535			Date: 03/23/2004


A DESCRIPTION OF THE REQUEST :
Class:   java.net.URLEncoder

uses

Class:   java.io.BufferedWriter

which has the following line in the constructor.

	lineSeparator =	(String) java.security.AccessController.doPrivileged(
               new sun.security.action.GetPropertyAction("line.separator"));

I am thinking that the lineSeparator should be defined as STATIC variable in the class and it should be initialized once to avoid subsequenct security check and duplicate read on a hashtable (which has synchronized get() method).

JUSTIFICATION :
We are having significant performance issue when trying to use URLEncoder and we found that multiple threads are trying to System.getProperty("line.separator") from BufferedWriter (System.getProperty() is reading from a Hashtable and it has a synchronized get(), thus causing huge performance issue for us).

Is it possible for you to get the line.separator as a private static variable and gets it value only once instead of getting it during every object creation.
(Incident Review ID: 192587) 
======================================================================