From 0d1ce0a79e1ab1193d741df52ededf5933d93115 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 2 Jun 2016 15:29:00 +0200 Subject: Use AtomicLong in ThreadId instead of synchronizing Change-Id: Ia10bab23b0cecb587cd3faa9c7e93b18384ecb88 Reviewed-on: https://gerrit.libreoffice.org/25827 Tested-by: Jenkins Reviewed-by: Noel Grandin --- jurt/com/sun/star/lib/uno/environments/remote/ThreadId.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'jurt/com') diff --git a/jurt/com/sun/star/lib/uno/environments/remote/ThreadId.java b/jurt/com/sun/star/lib/uno/environments/remote/ThreadId.java index 535d72782b68..f8dacc78cc48 100644 --- a/jurt/com/sun/star/lib/uno/environments/remote/ThreadId.java +++ b/jurt/com/sun/star/lib/uno/environments/remote/ThreadId.java @@ -19,18 +19,15 @@ package com.sun.star.lib.uno.environments.remote; -import com.sun.star.uno.UnoRuntime; import java.io.UnsupportedEncodingException; -import java.math.BigInteger; import java.util.Arrays; +import java.util.concurrent.atomic.AtomicLong; + +import com.sun.star.uno.UnoRuntime; public final class ThreadId { public static ThreadId createFresh() { - BigInteger c; - synchronized (PREFIX) { - c = count; - count = count.add(BigInteger.ONE); - } + long c = count.getAndIncrement(); try { return new ThreadId((PREFIX + c).getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { @@ -103,7 +100,7 @@ public final class ThreadId { } private static final String PREFIX = "java:" + UnoRuntime.getUniqueKey() + ":"; - private static BigInteger count = BigInteger.ZERO; + private static final AtomicLong count = new AtomicLong(0); private final byte[] id; private int hash = 0; -- cgit