[ 
https://issues.apache.org/jira/browse/OWB-1388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17382516#comment-17382516
 ] 

Romain Manni-Bucau commented on OWB-1388:
-----------------------------------------

Best is likely to use 
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#lineSeparator-- 
. Since it is about violations, it is always better to not keep it allocated 
until needed IMHO and it is not a big deal to hit synchronized there since it 
is not  a highly concurrent point nor an expected codepath except in dev (it 
stays a deployment error code path).

> ViolationMessageBuilder has System.getProperty call as instance variable 
> rather than static variable
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OWB-1388
>                 URL: https://issues.apache.org/jira/browse/OWB-1388
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Enterprise Web Beans, Simple Web Beans
>            Reporter: Raghunandan
>            Priority: Major
>
> *Problem*: Repeated instantiation of 
> [ViolationMessageBuilder.java|https://github.com/apache/openwebbeans/blob/master/webbeans-impl/src/main/java/org/apache/webbeans/exception/helper/ViolationMessageBuilder.java]
>  causes thread to block at java.util.Hashtable.
> Class :  
> [https://github.com/apache/openwebbeans/blob/master/webbeans-impl/src/main/java/org/apache/webbeans/exception/helper/ViolationMessageBuilder.java]
> Current field :  
>  _private_ _final String lineSeparator = 
> System.getProperty("line.separator");_
> _Currently it is getting instantiated every time 
> *{color:#FF0000}ViolationMessageBuilder{color}* is instantiated by the code._
>  
> *_Fix :_*
>  Change  it to static variable : 
> _private {color:#FF0000}static{color} final String lineSeparator = 
> System.getProperty("line.separator");_
>  This will prevent java.util.HashTable 
> (_System.getProperty("line.separator")_  being called every time 
> {color:#FF0000}ViolationMessageBuilder{color}  instantiated.
>  
> *Sample thread block noticed at high concurrency*
> java.lang.Thread.State: BLOCKED (on object monitor)
>                at 
> java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object;(Hashtable.java:363)
>                - waiting to lock <0x000000069a4fc6e0> (a java.util.Properties)
>                at 
> java.util.Properties.getProperty(Ljava/lang/String;)Ljava/lang/String;(Properties.java:1093)
>                at 
> java.lang.System.getProperty(Ljava/lang/String;)Ljava/lang/String;(System.java:732)
>                at 
> org.apache.webbeans.exception.helper.*{color:#FF0000}ViolationMessageBuilder{color}*{color:#FF0000}.<init>{color}()V(ViolationMessageBuilder.java:25)
>                at 
> org.apache.webbeans.exception.helper.ViolationMessageBuilder.newViolation([Ljava/lang/String;)Lorg/apache/webbeans/exception/helper/ViolationMessageBuilder;(ViolationMessageBuilder.java:34)
>                at 
> org.apache.webbeans.util.InjectionExceptionUtil.*throwUnsatisfiedResolutionException*(Ljava/lang/Class;Ljavax/enterprise/inject/spi/InjectionPoint;[Ljava/lang/annotation/Annotation;)V(InjectionExceptionUtil.java:51)
>                at 
> org.apache.webbeans.container.InjectionResolver.getInjectionPointBean(Ljavax/enterprise/inject/spi/InjectionPoint;)Ljavax/enterprise/inject/spi/Bean;(InjectionResolver.java:293)



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to