From 3fc17da7a585e96bcba86f1380bb05e54e460e70 Mon Sep 17 00:00:00 2001 From: coffeys Date: Tue, 14 Jun 2011 18:05:42 +0100 Subject: [PATCH] 7049774: UID construction appears to hang if time changed backwards Reviewed-by: alanb, dholmes, chegar, mduigou --- src/share/classes/java/rmi/server/UID.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/share/classes/java/rmi/server/UID.java b/src/share/classes/java/rmi/server/UID.java index f03586caf..b84e80d1b 100644 --- a/src/share/classes/java/rmi/server/UID.java +++ b/src/share/classes/java/rmi/server/UID.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -118,15 +118,17 @@ public final class UID implements Serializable { boolean done = false; while (!done) { long now = System.currentTimeMillis(); - if (now <= lastTime) { + if (now == lastTime) { // wait for time to change try { - Thread.currentThread().sleep(1); + Thread.sleep(1); } catch (InterruptedException e) { interrupted = true; } } else { - lastTime = now; + // If system time has gone backwards increase + // original by 1ms to maintain uniqueness + lastTime = (now < lastTime) ? lastTime+1 : now; lastCount = Short.MIN_VALUE; done = true; } -- GitLab