Issue #361: Fine tune synchronization in GfeScriptExecutor to prevent
massive backups in access to GfeScript instance map. Issue #361: Further modifications to GfeScriptExecutor and GfeScript to improve synchronization-caused back-logs. Change-Id: Ic33ef5e62d2bd1e19dd2cfedcfefe050cf7efe9e Former-commit-id:3cfa029f4b
[formerly9a75c87829
[formerly 679996850315f699d47633da5baf593c72ba7927]] Former-commit-id:9a75c87829
Former-commit-id:efc9e9000b
This commit is contained in:
parent
b8acb1912c
commit
d3d2046df0
2 changed files with 18 additions and 13 deletions
|
@ -191,7 +191,6 @@ public class GfeScript extends Thread {
|
|||
|
||||
public String waitFor() {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
while (isRunning()) {
|
||||
|
||||
Thread.sleep(200);
|
||||
|
|
|
@ -72,6 +72,7 @@ public class GfeScriptExecutor {
|
|||
private static Map<String, GfeScript> scriptMap = new ConcurrentHashMap<String, GfeScript>();
|
||||
|
||||
private static final FilenameFilter docFileFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".doc");
|
||||
}
|
||||
|
@ -111,22 +112,27 @@ public class GfeScriptExecutor {
|
|||
return "Error getting database configuration\n" + e.getMessage();
|
||||
}
|
||||
|
||||
GfeScript theScript = null;
|
||||
String key = null;
|
||||
for (String site : sites.keySet()) {
|
||||
key = scriptName + site;
|
||||
GfeScript theScript = null;
|
||||
String key = scriptName + site;
|
||||
// synchronize on the map here so multiple threads don't try
|
||||
// creating the same GfeScript object
|
||||
synchronized (scriptMap) {
|
||||
if (scriptMap.containsKey(key)) {
|
||||
scriptMap.get(key).waitFor();
|
||||
} else {
|
||||
GfeScript newScript = new GfeScript(scriptName, site);
|
||||
newScript.start();
|
||||
scriptMap.put(key, newScript);
|
||||
theScript = scriptMap.get(key);
|
||||
if (theScript == null) {
|
||||
theScript = new GfeScript(scriptName, site);
|
||||
theScript.start();
|
||||
scriptMap.put(key, theScript);
|
||||
}
|
||||
}
|
||||
theScript = scriptMap.get(key);
|
||||
theScript.execute(sites.get(site));
|
||||
String scriptRetVal = theScript.waitFor();
|
||||
|
||||
String scriptRetVal = null;
|
||||
// synchronize on the GfeScript object here so multiple threads
|
||||
// can't try to execute the same instance at once
|
||||
synchronized (theScript) {
|
||||
theScript.execute(sites.get(site));
|
||||
scriptRetVal = theScript.waitFor();
|
||||
}
|
||||
if (!scriptRetVal.equals(SUCCESS)) {
|
||||
if (retVal.equals(SUCCESS)) {
|
||||
retVal = scriptRetVal;
|
||||
|
|
Loading…
Add table
Reference in a new issue