@@ -369,7 +369,7 @@ public Sensor sensor(String name, Sensor.RecordingLevel recordingLevel, Sensor..
369369 * @param parents The parent sensors
370370 * @return The sensor that is created
371371 */
372- public synchronized Sensor sensor (String name , MetricConfig config , Sensor ... parents ) {
372+ public Sensor sensor (String name , MetricConfig config , Sensor ... parents ) {
373373 return this .sensor (name , config , Sensor .RecordingLevel .INFO , parents );
374374 }
375375
@@ -383,7 +383,7 @@ public synchronized Sensor sensor(String name, MetricConfig config, Sensor... pa
383383 * @param parents The parent sensors
384384 * @return The sensor that is created
385385 */
386- public synchronized Sensor sensor (String name , MetricConfig config , Sensor .RecordingLevel recordingLevel , Sensor ... parents ) {
386+ public Sensor sensor (String name , MetricConfig config , Sensor .RecordingLevel recordingLevel , Sensor ... parents ) {
387387 return sensor (name , config , Long .MAX_VALUE , recordingLevel , parents );
388388 }
389389
@@ -398,18 +398,23 @@ public synchronized Sensor sensor(String name, MetricConfig config, Sensor.Recor
398398 * @param recordingLevel The recording level.
399399 * @return The sensor that is created
400400 */
401- public synchronized Sensor sensor (String name , MetricConfig config , long inactiveSensorExpirationTimeSeconds , Sensor .RecordingLevel recordingLevel , Sensor ... parents ) {
401+ public Sensor sensor (String name , MetricConfig config , long inactiveSensorExpirationTimeSeconds , Sensor .RecordingLevel recordingLevel , Sensor ... parents ) {
402402 Sensor s = getSensor (name );
403403 if (s == null ) {
404- s = new Sensor (this , name , parents , config == null ? this .config : config , time , inactiveSensorExpirationTimeSeconds , recordingLevel );
405- this .sensors .put (name , s );
406- if (parents != null ) {
407- for (Sensor parent : parents ) {
408- List <Sensor > children = childrenSensors .computeIfAbsent (parent , k -> new ArrayList <>());
409- children .add (s );
404+ synchronized (this ) {
405+ s = getSensor (name );
406+ if (s == null ) {
407+ s = new Sensor (this , name , parents , config == null ? this .config : config , time , inactiveSensorExpirationTimeSeconds , recordingLevel );
408+ this .sensors .put (name , s );
409+ if (parents != null ) {
410+ for (Sensor parent : parents ) {
411+ List <Sensor > children = childrenSensors .computeIfAbsent (parent , k -> new ArrayList <>());
412+ children .add (s );
413+ }
414+ }
415+ log .trace ("Added sensor with name {}" , name );
410416 }
411417 }
412- log .trace ("Added sensor with name {}" , name );
413418 }
414419 return s ;
415420 }
@@ -424,7 +429,7 @@ public synchronized Sensor sensor(String name, MetricConfig config, long inactiv
424429 * @param parents The parent sensors
425430 * @return The sensor that is created
426431 */
427- public synchronized Sensor sensor (String name , MetricConfig config , long inactiveSensorExpirationTimeSeconds , Sensor ... parents ) {
432+ public Sensor sensor (String name , MetricConfig config , long inactiveSensorExpirationTimeSeconds , Sensor ... parents ) {
428433 return this .sensor (name , config , inactiveSensorExpirationTimeSeconds , Sensor .RecordingLevel .INFO , parents );
429434 }
430435
0 commit comments