7049774: UID construction appears to hang if time changed backwards
Reviewed-by: alanb, dholmes, chegar, mduigou
--- a/jdk/src/share/classes/java/rmi/server/UID.java Mon Jun 13 12:17:20 2011 -0700
+++ b/jdk/src/share/classes/java/rmi/server/UID.java Tue Jun 14 18:05:42 2011 +0100
@@ -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 @@
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;
}