hi
Richard
Just a quick question - Out of
curiosity, I took a look at
VMID (since I'd never heard of it) and then at UID
which
is called by
VMID.
In the UID class constructor for
the Sun JDK 1.3,
the line below
occurs withing a synchronized block:
Thread.currentThread().sleep(ONE_SECOND);
Is it ok to call sleep()
within in this manner within the
context
of an executing EJB? i.e. does this violate
the thread restrictions.
(I didnt have an EJB immediately at
hand setup to test)
Does this also raise a
performance question?
regards
Jim
Nicolson
-----------------------------------------
public
UID() {
synchronized (mutex)
{
if (lastCount == Short.MAX_VALUE) {
boolean done = false;
while (!done) {
time = System.currentTimeMillis();
if (time < lastTime+ONE_SECOND) {
// pause for a second to wait for time to change
try {
Thread.currentThread().sleep(ONE_SECOND);
} catch (java.lang.InterruptedException e) {
} // ignore exception
continue;
} else {
lastTime = time;
lastCount = Short.MIN_VALUE;
done = true;
}
}
} else {
time = lastTime;
}
unique = hostUnique;
count = lastCount++;
}
}
if (lastCount == Short.MAX_VALUE) {
boolean done = false;
while (!done) {
time = System.currentTimeMillis();
if (time < lastTime+ONE_SECOND) {
// pause for a second to wait for time to change
try {
Thread.currentThread().sleep(ONE_SECOND);
} catch (java.lang.InterruptedException e) {
} // ignore exception
continue;
} else {
lastTime = time;
lastCount = Short.MIN_VALUE;
done = true;
}
}
} else {
time = lastTime;
}
unique = hostUnique;
count = lastCount++;
}
}
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Richard Monson-Haefel
Sent: Tuesday, 28 August 2001 1:05 PM
To: [EMAIL PROTECTED]
Subject: Re: Primary Key Generation - chapter posted on TheServerSide.comNice work, Floyd. I think this chapter will be valuable to EJB developers. One thing I would change is to use Java RMI's UUID generator (java.rmi.dgc.VMID) instead of creating a custom one -- its already there so why not use it? I did, however, enjoy your explanation of UUID and I think people can learn a lot from that discussion. As a side note: I would never use another enterprise bean as the id generator because the overhead is unwarranted. Other then that I thought the chapter was excellent.[Jim Nicolson] snip...