Optimize synchronization in updatePrototypes(): keep out of synchronized section if possible

This commit is contained in:
hns 2005-03-24 18:24:51 +00:00
parent 7af9cc6a22
commit 0856559870

View file

@ -51,7 +51,7 @@ public final class RhinoCore implements ScopeProvider {
Hashtable prototypes;
// timestamp of last type update
long lastUpdate = 0;
volatile long lastUpdate = 0;
// the wrap factory
WrapFactory wrapper;
@ -310,7 +310,12 @@ public final class RhinoCore implements ScopeProvider {
* here is to check for update those prototypes which already have been compiled
* before. Others will be updated/compiled on demand.
*/
public synchronized void updatePrototypes() throws IOException {
public void updatePrototypes() throws IOException {
if ((System.currentTimeMillis() - lastUpdate) < 1000L) {
return;
}
synchronized(this) {
if ((System.currentTimeMillis() - lastUpdate) < 1000L) {
return;
}
@ -354,6 +359,7 @@ public final class RhinoCore implements ScopeProvider {
lastUpdate = System.currentTimeMillis();
}
}
/**
* Check one prototype for updates. Used by <code>upatePrototypes()</code>.