IDEMPIERE-312 Performance: Use JDK ThreadPool API for dynamically created thread

This commit is contained in:
Heng Sin Low 2012-07-02 14:03:10 +08:00
parent c19853b0ad
commit c611dd0830
2 changed files with 21 additions and 55 deletions

View File

@ -13,6 +13,7 @@ import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.util.Callback; import org.adempiere.util.Callback;
import org.adempiere.util.ContextRunnable;
import org.adempiere.util.IProcessUI; import org.adempiere.util.IProcessUI;
import org.adempiere.util.ServerContext; import org.adempiere.util.ServerContext;
import org.adempiere.webui.AdempiereWebUI; import org.adempiere.webui.AdempiereWebUI;
@ -326,27 +327,17 @@ public class ProcessDialog extends Window implements EventListener<Event>, IProc
public void runProcess() { public void runProcess() {
//prepare context for background thread //prepare context for background thread
Properties p = new Properties(); Properties context = ServerContext.getCurrentInstance();
Properties env = Env.getCtx(); if (context.get(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY) == null) {
for(Object key : env.keySet()) { Desktop desktop = this.getDesktop();
if (key instanceof String) { context.put(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY, desktop);
String sKey = (String) key; }
Object value = env.get(sKey);
if (value instanceof String) {
String sValue = (String) value;
p.put(sKey, sValue);
}
}
}
Desktop desktop = this.getDesktop();
p.put(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY, desktop);
processDialogRunnable = new ProcessDialogRunnable(p); processDialogRunnable = new ProcessDialogRunnable();
future = Adempiere.getThreadPoolExecutor().submit(processDialogRunnable); future = Adempiere.getThreadPoolExecutor().submit(processDialogRunnable);
} }
private void onComplete() { private void onComplete() {
Env.getCtx().putAll(processDialogRunnable.getProperties());
future = null; future = null;
processDialogRunnable = null; processDialogRunnable = null;
unlockUI(m_pi); unlockUI(m_pi);
@ -649,26 +640,18 @@ public class ProcessDialog extends Window implements EventListener<Event>, IProc
return m_isLocked; return m_isLocked;
} }
class ProcessDialogRunnable implements Runnable { class ProcessDialogRunnable extends ContextRunnable {
private Properties properties; ProcessDialogRunnable() {
super();
ProcessDialogRunnable(Properties properties) {
this.properties = properties;
} }
public void run() { protected void doRun() {
try { try {
ServerContext.setCurrentInstance(properties);
log.log(Level.INFO, "Process Info="+m_pi+" AD_Client_ID="+Env.getAD_Client_ID(Env.getCtx())); log.log(Level.INFO, "Process Info="+m_pi+" AD_Client_ID="+Env.getAD_Client_ID(Env.getCtx()));
WProcessCtl.process(ProcessDialog.this, m_WindowNo, parameterPanel, m_pi, null); WProcessCtl.process(ProcessDialog.this, m_WindowNo, parameterPanel, m_pi, null);
} finally { } finally {
ServerContext.dispose();
Executions.schedule(getDesktop(), ProcessDialog.this, new Event(ON_COMPLETE, ProcessDialog.this, null)); Executions.schedule(getDesktop(), ProcessDialog.this, new Event(ON_COMPLETE, ProcessDialog.this, null));
} }
}
protected Properties getProperties() {
return properties;
} }
} }

View File

@ -27,6 +27,7 @@ import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.util.Callback; import org.adempiere.util.Callback;
import org.adempiere.util.ContextRunnable;
import org.adempiere.util.IProcessUI; import org.adempiere.util.IProcessUI;
import org.adempiere.util.ServerContext; import org.adempiere.util.ServerContext;
import org.adempiere.webui.AdempiereWebUI; import org.adempiere.webui.AdempiereWebUI;
@ -369,22 +370,13 @@ public class ProcessModalDialog extends Window implements EventListener<Event>,
*/ */
public void runProcess() { public void runProcess() {
//prepare context for background thread //prepare context for background thread
Properties p = new Properties(); Properties context = ServerContext.getCurrentInstance();
Properties env = Env.getCtx(); if (context.get(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY) == null) {
for(Object key : env.keySet()) { Desktop desktop = this.getDesktop();
if (key instanceof String) { context.put(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY, desktop);
String sKey = (String) key;
Object value = env.get(sKey);
if (value instanceof String) {
String sValue = (String) value;
p.put(sKey, sValue);
}
}
} }
Desktop desktop = this.getDesktop();
p.put(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY, desktop);
processDialogRunnable = new ProcessDialogRunnable(p); processDialogRunnable = new ProcessDialogRunnable();
future = Adempiere.getThreadPoolExecutor().submit(processDialogRunnable); future = Adempiere.getThreadPoolExecutor().submit(processDialogRunnable);
} }
@ -431,7 +423,6 @@ public class ProcessModalDialog extends Window implements EventListener<Event>,
} }
private void onComplete() { private void onComplete() {
Env.getCtx().putAll(processDialogRunnable.getProperties());
future = null; future = null;
processDialogRunnable = null; processDialogRunnable = null;
unlockUI(m_pi); unlockUI(m_pi);
@ -481,26 +472,18 @@ public class ProcessModalDialog extends Window implements EventListener<Event>,
return m_pi; return m_pi;
} }
class ProcessDialogRunnable implements Runnable { class ProcessDialogRunnable extends ContextRunnable{
private Properties properties; ProcessDialogRunnable() {
super();
ProcessDialogRunnable(Properties properties) {
this.properties = properties;
} }
public void run() { protected void doRun() {
try { try {
ServerContext.setCurrentInstance(properties);
log.log(Level.INFO, "Process Info="+m_pi+" AD_Client_ID="+Env.getAD_Client_ID(Env.getCtx())); log.log(Level.INFO, "Process Info="+m_pi+" AD_Client_ID="+Env.getAD_Client_ID(Env.getCtx()));
WProcessCtl.process(ProcessModalDialog.this, m_WindowNo, parameterPanel, m_pi, null); WProcessCtl.process(ProcessModalDialog.this, m_WindowNo, parameterPanel, m_pi, null);
} finally { } finally {
ServerContext.dispose();
Executions.schedule(getDesktop(), ProcessModalDialog.this, new Event(ON_COMPLETE, ProcessModalDialog.this, null)); Executions.schedule(getDesktop(), ProcessModalDialog.this, new Event(ON_COMPLETE, ProcessModalDialog.this, null));
} }
}
protected Properties getProperties() {
return properties;
} }
} }