Optimize synchronization in updatePrototypes(): keep out of synchronized section if possible
This commit is contained in:
parent
7af9cc6a22
commit
0856559870
1 changed files with 40 additions and 34 deletions
|
@ -51,7 +51,7 @@ public final class RhinoCore implements ScopeProvider {
|
||||||
Hashtable prototypes;
|
Hashtable prototypes;
|
||||||
|
|
||||||
// timestamp of last type update
|
// timestamp of last type update
|
||||||
long lastUpdate = 0;
|
volatile long lastUpdate = 0;
|
||||||
|
|
||||||
// the wrap factory
|
// the wrap factory
|
||||||
WrapFactory wrapper;
|
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
|
* here is to check for update those prototypes which already have been compiled
|
||||||
* before. Others will be updated/compiled on demand.
|
* 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) {
|
if ((System.currentTimeMillis() - lastUpdate) < 1000L) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -354,6 +359,7 @@ public final class RhinoCore implements ScopeProvider {
|
||||||
|
|
||||||
lastUpdate = System.currentTimeMillis();
|
lastUpdate = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check one prototype for updates. Used by <code>upatePrototypes()</code>.
|
* Check one prototype for updates. Used by <code>upatePrototypes()</code>.
|
||||||
|
|
Loading…
Add table
Reference in a new issue