IDEMPIERE-502 Use single thread pool for client and server process

This commit is contained in:
Heng Sin Low 2012-11-14 10:11:17 +08:00
parent ad50b501b2
commit 640888051a
9 changed files with 260 additions and 390 deletions

View File

@ -23,8 +23,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
@ -50,6 +49,7 @@ import org.compiere.util.Ini;
import org.compiere.util.Login; import org.compiere.util.Login;
import org.compiere.util.SecureEngine; import org.compiere.util.SecureEngine;
import org.compiere.util.SecureInterface; import org.compiere.util.SecureInterface;
import org.compiere.util.Trx;
import org.compiere.util.Util; import org.compiere.util.Util;
import org.eclipse.core.runtime.IProduct; import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
@ -111,7 +111,7 @@ public final class Adempiere
private static CLogger log = null; private static CLogger log = null;
/** Thread pool **/ /** Thread pool **/
private static ThreadPoolExecutor threadPoolExecutor = null; private static ScheduledThreadPoolExecutor threadPoolExecutor = null;
/** A list of event listeners for this component. */ /** A list of event listeners for this component. */
private static EventListenerList m_listenerList = new EventListenerList(); private static EventListenerList m_listenerList = new EventListenerList();
@ -553,8 +553,10 @@ public final class Adempiere
} // startup } // startup
private static void createThreadPool() { private static void createThreadPool() {
int min = 10; int max = Runtime.getRuntime().availableProcessors() * 3;
int max = 200; int min = max / 2;
int defaultMax = max;
int defaultMin = min;
Properties properties = Ini.getProperties(); Properties properties = Ini.getProperties();
String maxSize = properties.getProperty("MaxThreadPoolSize"); String maxSize = properties.getProperty("MaxThreadPoolSize");
String minSize = properties.getProperty("MinThreadPoolSize"); String minSize = properties.getProperty("MinThreadPoolSize");
@ -572,14 +574,19 @@ public final class Adempiere
max = min; max = min;
} }
if (max <= 0) { if (max <= 0) {
max = 200; max = defaultMax;
} }
if (min < 0) { if (min < 0) {
min = 10; min = defaultMin;
} }
// start thread pool // start thread pool
threadPoolExecutor = new ThreadPoolExecutor(min, max, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>()); threadPoolExecutor = new ScheduledThreadPoolExecutor(min);
threadPoolExecutor.setMaximumPoolSize(max);
threadPoolExecutor.setKeepAliveTime(10, TimeUnit.MINUTES);
threadPoolExecutor.allowCoreThreadTimeOut(true); threadPoolExecutor.allowCoreThreadTimeOut(true);
Trx.startTrxMonitor();
} }
/** /**
@ -660,7 +667,7 @@ public final class Adempiere
} }
} }
public static ThreadPoolExecutor getThreadPoolExecutor() { public static ScheduledThreadPoolExecutor getThreadPoolExecutor() {
return threadPoolExecutor; return threadPoolExecutor;
} }

View File

@ -25,9 +25,11 @@ import java.sql.Savepoint;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.compiere.Adempiere;
import org.compiere.model.PO; import org.compiere.model.PO;
/** /**
@ -85,13 +87,9 @@ public class Trx implements VetoableChangeListener
private static Trx.TrxMonitor s_monitor = new Trx.TrxMonitor(); private static Trx.TrxMonitor s_monitor = new Trx.TrxMonitor();
static public static void startTrxMonitor()
{ {
Thread monitorThread = new Thread(s_monitor); Adempiere.getThreadPoolExecutor().scheduleWithFixedDelay(s_monitor, 5, 5, TimeUnit.MINUTES);
monitorThread.setDaemon(true);
monitorThread.setPriority(Thread.MIN_PRIORITY);
monitorThread.setName("Trx-Monitor");
monitorThread.start();
} }
/** /**
@ -610,8 +608,6 @@ public class Trx implements VetoableChangeListener
{ {
public void run() public void run()
{
for(;;)
{ {
if (Trx.s_cache != null && !Trx.s_cache.isEmpty()) if (Trx.s_cache != null && !Trx.s_cache.isEmpty())
{ {
@ -629,15 +625,8 @@ public class Trx implements VetoableChangeListener
} }
} }
} }
try {
Thread.sleep(1000 * 10);
} catch (InterruptedException e) {
Thread.interrupted();
} }
} }
}
}
private boolean isLocalTrx(String trxName) private boolean isLocalTrx(String trxName)
{ {

View File

@ -26,13 +26,11 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.acct.DocManager; import org.compiere.acct.DocManager;
import org.compiere.model.AdempiereProcessor2;
import org.compiere.model.MAcctProcessor; import org.compiere.model.MAcctProcessor;
import org.compiere.model.MAcctProcessorLog; import org.compiere.model.MAcctProcessorLog;
import org.compiere.model.MAcctSchema; import org.compiere.model.MAcctSchema;
import org.compiere.model.MClient; import org.compiere.model.MClient;
import org.compiere.model.MCost; import org.compiere.model.MCost;
import org.compiere.model.MSchedule;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.TimeUtil; import org.compiere.util.TimeUtil;
@ -130,7 +128,7 @@ public class AcctProcessor extends AdempiereServer
pstmt.setInt(1, m_model.getAD_Client_ID()); pstmt.setInt(1, m_model.getAD_Client_ID());
pstmt.setBigDecimal(2, value); pstmt.setBigDecimal(2, value);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (!isInterrupted() && rs.next()) while (!Thread.currentThread().isInterrupted() && rs.next())
{ {
BigDecimal processedOn = rs.getBigDecimal(1); BigDecimal processedOn = rs.getBigDecimal(1);
if (!listProcessedOn.contains(processedOn)) if (!listProcessedOn.contains(processedOn))
@ -198,7 +196,7 @@ public class AcctProcessor extends AdempiereServer
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, getName() + ": " + TableName, e); log.log(Level.SEVERE, TableName, e);
ok = false; ok = false;
} }
if (!ok) if (!ok)

View File

@ -43,7 +43,7 @@ import org.compiere.wf.MWorkflowProcessor;
* @author Jorg Janke * @author Jorg Janke
* @version $Id: AdempiereServer.java,v 1.3 2006/10/09 00:23:26 jjanke Exp $ * @version $Id: AdempiereServer.java,v 1.3 2006/10/09 00:23:26 jjanke Exp $
*/ */
public abstract class AdempiereServer extends Thread public abstract class AdempiereServer implements Runnable
{ {
/** /**
* Create New Server Thead * Create New Server Thead
@ -78,7 +78,6 @@ public abstract class AdempiereServer extends Thread
*/ */
protected AdempiereServer (AdempiereProcessor model, int initialNap) protected AdempiereServer (AdempiereProcessor model, int initialNap)
{ {
super (AdempiereServerGroup.get(), null, model.getName(), 0);
p_model = model; p_model = model;
m_ctx = new Properties(model.getCtx()); m_ctx = new Properties(model.getCtx());
if (p_system == null) if (p_system == null)
@ -86,7 +85,16 @@ public abstract class AdempiereServer extends Thread
p_client = MClient.get(m_ctx); p_client = MClient.get(m_ctx);
Env.setContext(m_ctx, "#AD_Client_ID", p_client.getAD_Client_ID()); Env.setContext(m_ctx, "#AD_Client_ID", p_client.getAD_Client_ID());
m_initialNap = initialNap; m_initialNap = initialNap;
// log.info(model.getName() + " - " + getThreadGroup());
Timestamp dateNextRun = getDateNextRun(true);
if (dateNextRun != null)
m_nextWork = dateNextRun.getTime();
long now = System.currentTimeMillis();
if (m_nextWork > now)
{
m_sleepMS = m_nextWork - now;
}
} // ServerBase } // ServerBase
/** The Processor Model */ /** The Processor Model */
@ -97,7 +105,7 @@ public abstract class AdempiereServer extends Thread
/** Milliseconds to sleep - 10 Min default */ /** Milliseconds to sleep - 10 Min default */
protected long m_sleepMS = 600000; protected long m_sleepMS = 600000;
/** Sleeping */ /** Sleeping */
private volatile boolean m_sleeping = false; private volatile boolean m_sleeping = true;
/** Server start time */ /** Server start time */
protected long m_start = 0; protected long m_start = 0;
/** Number of Work executions */ /** Number of Work executions */
@ -137,40 +145,17 @@ public abstract class AdempiereServer extends Thread
return m_sleepMS; return m_sleepMS;
} // getSleepMS } // getSleepMS
public long getInitialNap()
/**
* Sleep for set time
* @return true if not interrupted
*/
public boolean sleep()
{ {
if (isInterrupted()) return m_initialNap;
{
log.info (getName() + ": interrupted");
return false;
} }
log.fine(getName() + ": sleeping " + TimeUtil.formatElapsed(m_sleepMS));
m_sleeping = true;
try
{
sleep (m_sleepMS);
}
catch (InterruptedException e)
{
log.info (getName() + ": interrupted");
m_sleeping = false;
return false;
}
m_sleeping = false;
return true;
} // sleep
/** /**
* Run Now * Run Now
*/ */
public void runNow() public void runNow()
{ {
log.info(getName()); m_sleeping = false;
p_startWork = System.currentTimeMillis(); p_startWork = System.currentTimeMillis();
doWork(); doWork();
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -183,7 +168,9 @@ public abstract class AdempiereServer extends Thread
p_model.setDateLastRun(new Timestamp(now)); p_model.setDateLastRun(new Timestamp(now));
p_model.saveEx(); p_model.saveEx();
// //
log.fine(getName() + ": " + getStatistics()); if (log.isLoggable(Level.FINE))
log.fine(getStatistics());
m_sleeping = true;
} // runNow } // runNow
/************************************************************************** /**************************************************************************
@ -191,43 +178,14 @@ public abstract class AdempiereServer extends Thread
*/ */
public void run () public void run ()
{ {
try m_sleeping = false;
{ if (m_start == 0)
log.fine(getName() + ": pre-nap - " + m_initialNap);
sleep (m_initialNap * 1000);
}
catch (InterruptedException e)
{
log.log(Level.SEVERE, getName() + ": pre-nap interrupted", e);
return;
}
m_start = System.currentTimeMillis(); m_start = System.currentTimeMillis();
while (true)
{
if (m_nextWork == 0)
{
Timestamp dateNextRun = getDateNextRun(true);
if (dateNextRun != null)
m_nextWork = dateNextRun.getTime();
}
long now = System.currentTimeMillis();
if (m_nextWork > now)
{
m_sleepMS = m_nextWork - now;
if (!sleep ())
break;
}
if (isInterrupted())
{
log.info (getName() + ": interrupted");
break;
}
// --------------- // ---------------
p_startWork = System.currentTimeMillis(); p_startWork = System.currentTimeMillis();
doWork(); doWork();
now = System.currentTimeMillis(); long now = System.currentTimeMillis();
// --------------- // ---------------
p_runCount++; p_runCount++;
@ -250,17 +208,13 @@ public abstract class AdempiereServer extends Thread
p_model.getFrequency(), p_model.getCronPattern()); p_model.getFrequency(), p_model.getCronPattern());
m_sleepMS = m_nextWork - now; m_sleepMS = m_nextWork - now;
log.info(getName() + " Next run: " + new Timestamp(m_nextWork) + " sleep " + m_sleepMS); if (log.isLoggable(Level.INFO))
log.info(" Next run: " + new Timestamp(m_nextWork) + " sleep " + m_sleepMS);
// //
p_model.setDateLastRun(lastRun); p_model.setDateLastRun(lastRun);
p_model.setDateNextRun(new Timestamp(m_nextWork)); p_model.setDateNextRun(new Timestamp(m_nextWork));
p_model.saveEx(); p_model.saveEx();
// m_sleeping = true;
log.fine(getName() + ": " + getStatistics());
if (!sleep())
break;
}
m_start = 0;
} // run } // run
/** /**
@ -347,11 +301,8 @@ public abstract class AdempiereServer extends Thread
*/ */
public String toString () public String toString ()
{ {
StringBuffer sb = new StringBuffer (getName()) StringBuffer sb = new StringBuffer ()
.append (",Prio=").append(getPriority()) .append ("Sleeping=").append(m_sleeping)
.append (",").append (getThreadGroup())
.append (",Alive=").append(isAlive())
.append (",Sleeping=").append(m_sleeping)
.append (",Last=").append(getDateLastRun()); .append (",Last=").append(getDateLastRun());
if (m_sleeping) if (m_sleeping)
sb.append (",Next=").append(getDateNextRun(false)); sb.append (",Next=").append(getDateNextRun(false));
@ -392,6 +343,16 @@ public abstract class AdempiereServer extends Thread
} // getLogs } // getLogs
protected boolean isInterrupted() {
return Thread.currentThread().isInterrupted();
}
public String getName() {
return p_model.getName();
}
public static boolean isOKtoRunOnIP(AdempiereProcessor model) { public static boolean isOKtoRunOnIP(AdempiereProcessor model) {
if (model instanceof AdempiereProcessor2) { if (model instanceof AdempiereProcessor2) {
int AD_Schedule_ID = ((AdempiereProcessor2)model).getAD_Schedule_ID(); int AD_Schedule_ID = ((AdempiereProcessor2)model).getAD_Schedule_ID();

View File

@ -20,6 +20,8 @@ import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.base.Service; import org.adempiere.base.Service;
@ -75,7 +77,7 @@ public class AdempiereServerMgr
} // AdempiereServerMgr } // AdempiereServerMgr
/** The Servers */ /** The Servers */
private ArrayList<AdempiereServer> m_servers = new ArrayList<AdempiereServer>(); private ArrayList<ServerWrapper> m_servers = new ArrayList<ServerWrapper>();
/** Context */ /** Context */
private Properties m_ctx = Env.getCtx(); private Properties m_ctx = Env.getCtx();
/** Start */ /** Start */
@ -107,7 +109,7 @@ public class AdempiereServerMgr
{ {
log.info(""); log.info("");
int noServers = 0; int noServers = 0;
m_servers=new ArrayList<AdempiereServer>(); m_servers=new ArrayList<ServerWrapper>();
// Accounting // Accounting
MAcctProcessor[] acctModels = MAcctProcessor.getActive(m_ctx); MAcctProcessor[] acctModels = MAcctProcessor.getActive(m_ctx);
for (int i = 0; i < acctModels.length; i++) for (int i = 0; i < acctModels.length; i++)
@ -115,9 +117,9 @@ public class AdempiereServerMgr
MAcctProcessor pModel = acctModels[i]; MAcctProcessor pModel = acctModels[i];
AdempiereServer server = AdempiereServer.create(pModel); AdempiereServer server = AdempiereServer.create(pModel);
if (server != null) { if (server != null) {
server.start(); // server.start();
server.setPriority(Thread.NORM_PRIORITY-2); // server.setPriority(Thread.NORM_PRIORITY-2);
m_servers.add(server); m_servers.add(new ServerWrapper(server));
} }
} }
// Request // Request
@ -127,9 +129,9 @@ public class AdempiereServerMgr
MRequestProcessor pModel = requestModels[i]; MRequestProcessor pModel = requestModels[i];
AdempiereServer server = AdempiereServer.create(pModel); AdempiereServer server = AdempiereServer.create(pModel);
if (server != null) { if (server != null) {
server.start(); // server.start();
server.setPriority(Thread.NORM_PRIORITY-2); // server.setPriority(Thread.NORM_PRIORITY-2);
m_servers.add(server); m_servers.add(new ServerWrapper(server));
} }
} }
// Workflow // Workflow
@ -139,9 +141,9 @@ public class AdempiereServerMgr
MWorkflowProcessor pModel = workflowModels[i]; MWorkflowProcessor pModel = workflowModels[i];
AdempiereServer server = AdempiereServer.create(pModel); AdempiereServer server = AdempiereServer.create(pModel);
if (server != null) { if (server != null) {
server.start(); // server.start();
server.setPriority(Thread.NORM_PRIORITY-2); // server.setPriority(Thread.NORM_PRIORITY-2);
m_servers.add(server); m_servers.add(new ServerWrapper(server));
} }
} }
// Alert // Alert
@ -151,9 +153,9 @@ public class AdempiereServerMgr
MAlertProcessor pModel = alertModels[i]; MAlertProcessor pModel = alertModels[i];
AdempiereServer server = AdempiereServer.create(pModel); AdempiereServer server = AdempiereServer.create(pModel);
if (server != null) { if (server != null) {
server.start(); // server.start();
server.setPriority(Thread.NORM_PRIORITY-2); // server.setPriority(Thread.NORM_PRIORITY-2);
m_servers.add(server); m_servers.add(new ServerWrapper(server));
} }
} }
// Scheduler // Scheduler
@ -163,9 +165,9 @@ public class AdempiereServerMgr
MScheduler pModel = schedulerModels[i]; MScheduler pModel = schedulerModels[i];
AdempiereServer server = AdempiereServer.create(pModel); AdempiereServer server = AdempiereServer.create(pModel);
if (server != null) { if (server != null) {
server.start(); // server.start();
server.setPriority(Thread.NORM_PRIORITY-2); // server.setPriority(Thread.NORM_PRIORITY-2);
m_servers.add(server); m_servers.add(new ServerWrapper(server));
} }
} }
// LDAP // LDAP
@ -175,9 +177,9 @@ public class AdempiereServerMgr
MLdapProcessor lp = ldapModels[i]; MLdapProcessor lp = ldapModels[i];
AdempiereServer server = AdempiereServer.create(lp); AdempiereServer server = AdempiereServer.create(lp);
if (server != null) { if (server != null) {
server.start(); // server.start();
server.setPriority(Thread.NORM_PRIORITY-1); // server.setPriority(Thread.NORM_PRIORITY-1);
m_servers.add(server); m_servers.add(new ServerWrapper(server));
} }
} }
@ -192,9 +194,9 @@ public class AdempiereServerMgr
{ {
for (AdempiereServer server : servers) for (AdempiereServer server : servers)
{ {
server.start(); // server.start();
server.setPriority(Thread.NORM_PRIORITY-1); // server.setPriority(Thread.NORM_PRIORITY-1);
m_servers.add(server); m_servers.add(new ServerWrapper(server));
} }
} }
} }
@ -220,47 +222,17 @@ public class AdempiereServerMgr
public boolean startAll() public boolean startAll()
{ {
log.info (""); log.info ("");
AdempiereServer[] servers = getInActive(); ServerWrapper[] servers = getInActive();
for (int i = 0; i < servers.length; i++) for (int i = 0; i < servers.length; i++)
{ {
AdempiereServer server = servers[i]; ServerWrapper server = servers[i];
try try
{ {
if (server.isAlive()) if (server.scheduleFuture != null || !server.scheduleFuture.isDone())
continue; continue;
// Wait until dead
if (server.isInterrupted())
{
int maxWait = 10; // 10 iterations = 1 sec
while (server.isAlive())
{
if (maxWait-- == 0)
{
log.severe ("Wait timeout for interruped " + server);
break;
}
try
{
Thread.sleep(100); // 1/10 sec
}
catch (InterruptedException e)
{
log.log(Level.SEVERE, "While sleeping", e);
}
}
}
// Do start // Do start
if (!server.isAlive())
{
// replace // replace
server = AdempiereServer.create (server.getModel());
if (server == null)
m_servers.remove(i);
else
m_servers.set(i, server);
server.start(); server.start();
server.setPriority(Thread.NORM_PRIORITY-2);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -273,10 +245,10 @@ public class AdempiereServerMgr
int noStopped = 0; int noStopped = 0;
for (int i = 0; i < servers.length; i++) for (int i = 0; i < servers.length; i++)
{ {
AdempiereServer server = servers[i]; ServerWrapper server = servers[i];
try try
{ {
if (server.isAlive()) if (server.scheduleFuture != null && !server.scheduleFuture.isDone())
{ {
log.info("Alive: " + server); log.info("Alive: " + server);
noRunning++; noRunning++;
@ -294,7 +266,6 @@ public class AdempiereServerMgr
} }
} }
log.fine("Running=" + noRunning + ", Stopped=" + noStopped); log.fine("Running=" + noRunning + ", Stopped=" + noStopped);
AdempiereServerGroup.get().dump();
return noStopped == 0; return noStopped == 0;
} // startAll } // startAll
@ -305,24 +276,16 @@ public class AdempiereServerMgr
*/ */
public boolean start (String serverID) public boolean start (String serverID)
{ {
AdempiereServer server = getServer(serverID); ServerWrapper server = getServer(serverID);
if (server == null) if (server == null)
return false; return false;
if (server.isAlive()) if (server.scheduleFuture != null && !server.scheduleFuture.isDone())
return true; return true;
try try
{ {
// replace // replace
int index = m_servers.indexOf(server);
server = AdempiereServer.create (server.getModel());
if (server == null)
m_servers.remove(index);
else
m_servers.set(index, server);
server.start(); server.start();
server.setPriority(Thread.NORM_PRIORITY-2);
Thread.yield();
} }
catch (Exception e) catch (Exception e)
{ {
@ -330,10 +293,7 @@ public class AdempiereServerMgr
return false; return false;
} }
log.info(server.toString()); log.info(server.toString());
AdempiereServerGroup.get().dump(); return (server.scheduleFuture != null && !server.scheduleFuture.isDone());
if (server == null)
return false;
return server.isAlive();
} // startIt } // startIt
/** /**
@ -343,17 +303,16 @@ public class AdempiereServerMgr
public boolean stopAll() public boolean stopAll()
{ {
log.info (""); log.info ("");
AdempiereServer[] servers = getActive(); ServerWrapper[] servers = getActive();
// Interrupt // Interrupt
for (int i = 0; i < servers.length; i++) for (int i = 0; i < servers.length; i++)
{ {
AdempiereServer server = servers[i]; ServerWrapper server = servers[i];
try try
{ {
if (server.isAlive() && !server.isInterrupted()) if (server.scheduleFuture != null && !server.scheduleFuture.isDone())
{ {
server.setPriority(Thread.MAX_PRIORITY-1); server.scheduleFuture.cancel(true);
server.interrupt();
} }
} }
catch (Exception e) catch (Exception e)
@ -366,11 +325,11 @@ public class AdempiereServerMgr
// Wait for death // Wait for death
for (int i = 0; i < servers.length; i++) for (int i = 0; i < servers.length; i++)
{ {
AdempiereServer server = servers[i]; ServerWrapper server = servers[i];
try try
{ {
int maxWait = 10; // 10 iterations = 1 sec int maxWait = 10; // 10 iterations = 1 sec
while (server.isAlive()) while (server.scheduleFuture != null && !server.scheduleFuture.isDone())
{ {
if (maxWait-- == 0) if (maxWait-- == 0)
{ {
@ -391,10 +350,10 @@ public class AdempiereServerMgr
int noStopped = 0; int noStopped = 0;
for (int i = 0; i < servers.length; i++) for (int i = 0; i < servers.length; i++)
{ {
AdempiereServer server = servers[i]; ServerWrapper server = servers[i];
try try
{ {
if (server.isAlive()) if (server.scheduleFuture != null && !server.scheduleFuture.isDone())
{ {
log.warning ("Alive: " + server); log.warning ("Alive: " + server);
noRunning++; noRunning++;
@ -423,15 +382,15 @@ public class AdempiereServerMgr
*/ */
public boolean stop (String serverID) public boolean stop (String serverID)
{ {
AdempiereServer server = getServer(serverID); ServerWrapper server = getServer(serverID);
if (server == null) if (server == null)
return false; return false;
if (!server.isAlive()) if (server.scheduleFuture == null || server.scheduleFuture.isDone())
return true; return true;
try try
{ {
server.interrupt(); server.scheduleFuture.cancel(true);
Thread.sleep(10); // 1/100 sec Thread.sleep(10); // 1/100 sec
} }
catch (Exception e) catch (Exception e)
@ -440,8 +399,7 @@ public class AdempiereServerMgr
return false; return false;
} }
log.info(server.toString()); log.info(server.toString());
AdempiereServerGroup.get().dump(); return (server.scheduleFuture == null || server.scheduleFuture.isDone());
return !server.isAlive();
} // stop } // stop
@ -459,16 +417,16 @@ public class AdempiereServerMgr
* Get Active Servers * Get Active Servers
* @return array of active servers * @return array of active servers
*/ */
protected AdempiereServer[] getActive() protected ServerWrapper[] getActive()
{ {
ArrayList<AdempiereServer> list = new ArrayList<AdempiereServer>(); ArrayList<ServerWrapper> list = new ArrayList<ServerWrapper>();
for (int i = 0; i < m_servers.size(); i++) for (int i = 0; i < m_servers.size(); i++)
{ {
AdempiereServer server = (AdempiereServer)m_servers.get(i); ServerWrapper server = (ServerWrapper)m_servers.get(i);
if (server != null && server.isAlive() && !server.isInterrupted()) if (server != null && server.scheduleFuture != null && !server.scheduleFuture.isDone())
list.add (server); list.add (server);
} }
AdempiereServer[] retValue = new AdempiereServer[list.size ()]; ServerWrapper[] retValue = new ServerWrapper[list.size ()];
list.toArray (retValue); list.toArray (retValue);
return retValue; return retValue;
} // getActive } // getActive
@ -477,16 +435,16 @@ public class AdempiereServerMgr
* Get InActive Servers * Get InActive Servers
* @return array of inactive servers * @return array of inactive servers
*/ */
protected AdempiereServer[] getInActive() protected ServerWrapper[] getInActive()
{ {
ArrayList<AdempiereServer> list = new ArrayList<AdempiereServer>(); ArrayList<ServerWrapper> list = new ArrayList<ServerWrapper>();
for (int i = 0; i < m_servers.size(); i++) for (int i = 0; i < m_servers.size(); i++)
{ {
AdempiereServer server = (AdempiereServer)m_servers.get(i); ServerWrapper server = m_servers.get(i);
if (server != null && (!server.isAlive() || !server.isInterrupted())) if (server != null && (server.scheduleFuture == null || server.scheduleFuture.isDone()))
list.add (server); list.add (server);
} }
AdempiereServer[] retValue = new AdempiereServer[list.size()]; ServerWrapper[] retValue = new ServerWrapper[list.size()];
list.toArray (retValue); list.toArray (retValue);
return retValue; return retValue;
} // getInActive } // getInActive
@ -495,9 +453,9 @@ public class AdempiereServerMgr
* Get all Servers * Get all Servers
* @return array of servers * @return array of servers
*/ */
public AdempiereServer[] getAll() public ServerWrapper[] getAll()
{ {
AdempiereServer[] retValue = new AdempiereServer[m_servers.size()]; ServerWrapper[] retValue = new ServerWrapper[m_servers.size()];
m_servers.toArray (retValue); m_servers.toArray (retValue);
return retValue; return retValue;
} // getAll } // getAll
@ -507,14 +465,14 @@ public class AdempiereServerMgr
* @param serverID server id * @param serverID server id
* @return server or null * @return server or null
*/ */
public AdempiereServer getServer (String serverID) public ServerWrapper getServer (String serverID)
{ {
if (serverID == null) if (serverID == null)
return null; return null;
for (int i = 0; i < m_servers.size(); i++) for (int i = 0; i < m_servers.size(); i++)
{ {
AdempiereServer server = (AdempiereServer)m_servers.get(i); ServerWrapper server = m_servers.get(i);
if (serverID.equals(server.getServerID())) if (serverID.equals(server.server.getServerID()))
return server; return server;
} }
return null; return null;
@ -553,8 +511,8 @@ public class AdempiereServerMgr
int noStopped = 0; int noStopped = 0;
for (int i = 0; i < m_servers.size(); i++) for (int i = 0; i < m_servers.size(); i++)
{ {
AdempiereServer server = (AdempiereServer)m_servers.get(i); ServerWrapper server = m_servers.get(i);
if (server.isAlive()) if (server.scheduleFuture != null && !server.scheduleFuture.isDone())
noRunning++; noRunning++;
else else
noStopped++; noStopped++;
@ -574,4 +532,38 @@ public class AdempiereServerMgr
return m_start; return m_start;
} // getStartTime } // getStartTime
public static class ServerWrapper implements Runnable
{
protected AdempiereServer server;
protected volatile ScheduledFuture<?> scheduleFuture;
public ServerWrapper(AdempiereServer server) {
this.server = server;
start();
}
public void start() {
scheduleFuture = Adempiere.getThreadPoolExecutor().schedule(this, server.getInitialNap() * 1000 + server.getSleepMS(), TimeUnit.MILLISECONDS);
}
@Override
public void run() {
server.run();
scheduleFuture = Adempiere.getThreadPoolExecutor().schedule(this, server.getSleepMS(), TimeUnit.MILLISECONDS);
}
public AdempiereServer getServer() {
return server;
}
public boolean isAlive() {
return scheduleFuture != null && !scheduleFuture.isDone();
}
public boolean isInterrupted() {
return scheduleFuture != null && scheduleFuture.isCancelled();
}
}
} // AdempiereServerMgr } // AdempiereServerMgr

View File

@ -454,8 +454,8 @@ public class AlertProcessor extends AdempiereServer
Adempiere.startup(true); Adempiere.startup(true);
MAlertProcessor model = new MAlertProcessor (Env.getCtx(), 100, null); MAlertProcessor model = new MAlertProcessor (Env.getCtx(), 100, null);
AlertProcessor ap = new AlertProcessor(model); AlertProcessor ap = new AlertProcessor(model);
ap.start(); AdempiereServerMgr.ServerWrapper wrapper = new AdempiereServerMgr.ServerWrapper(ap);
wrapper.start();
} }

View File

@ -20,7 +20,6 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
@ -65,9 +64,9 @@ import org.compiere.model.AdempiereProcessorLog;
import org.compiere.model.MClient; import org.compiere.model.MClient;
import org.compiere.model.MStore; import org.compiere.model.MStore;
import org.compiere.model.MSystem; import org.compiere.model.MSystem;
import org.compiere.server.AdempiereServer;
import org.compiere.server.AdempiereServerGroup; import org.compiere.server.AdempiereServerGroup;
import org.compiere.server.AdempiereServerMgr; import org.compiere.server.AdempiereServerMgr;
import org.compiere.server.AdempiereServerMgr.ServerWrapper;
import org.compiere.util.CLogFile; import org.compiere.util.CLogFile;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
@ -181,8 +180,8 @@ public class AdempiereMonitor extends HttpServlet
return false; return false;
log.info ("ServerID=" + serverID); log.info ("ServerID=" + serverID);
AdempiereServer server = m_serverMgr.getServer(serverID); ServerWrapper server = m_serverMgr.getServer(serverID);
if (server == null) if (server == null || server.getServer() == null)
{ {
m_message = new p(); m_message = new p();
m_message.addElement(new strong("Server not found: ")); m_message.addElement(new strong("Server not found: "));
@ -199,7 +198,7 @@ public class AdempiereMonitor extends HttpServlet
para.addElement(link); para.addElement(link);
b.addElement(para); b.addElement(para);
// //
b.addElement(new h2(server.getName())); b.addElement(new h2(server.getServer().getName()));
// //
table table = new table(); table table = new table();
table.setBorder(1); table.setBorder(1);
@ -216,7 +215,7 @@ public class AdempiereMonitor extends HttpServlet
// line.addElement(new th().addElement("Description")); // line.addElement(new th().addElement("Description"));
table.addElement(line); table.addElement(line);
AdempiereProcessorLog[] logs = server.getLogs(); AdempiereProcessorLog[] logs = server.getServer().getLogs();
for (int i = 0; i < logs.length; i++) for (int i = 0; i < logs.length; i++)
{ {
AdempiereProcessorLog pLog = logs[i]; AdempiereProcessorLog pLog = logs[i];
@ -252,8 +251,8 @@ public class AdempiereMonitor extends HttpServlet
return false; return false;
log.info ("ServerID=" + serverID); log.info ("ServerID=" + serverID);
AdempiereServer server = m_serverMgr.getServer(serverID); ServerWrapper server = m_serverMgr.getServer(serverID);
if (server == null) if (server == null || server.getServer() == null)
{ {
m_message = new p(); m_message = new p();
m_message.addElement(new strong("Server not found: ")); m_message.addElement(new strong("Server not found: "));
@ -261,7 +260,7 @@ public class AdempiereMonitor extends HttpServlet
return false; return false;
} }
// //
server.runNow(); server.getServer().runNow();
// //
return true; return true;
} // processRunParameter } // processRunParameter
@ -306,8 +305,8 @@ public class AdempiereMonitor extends HttpServlet
this.createSummaryPage(request, response,true); this.createSummaryPage(request, response,true);
m_dirAccessList = getDirAcessList(); m_dirAccessList = getDirAcessList();
} else { } else {
AdempiereServer server = m_serverMgr.getServer(serverID); ServerWrapper server = m_serverMgr.getServer(serverID);
if (server == null) { if (server == null || server.getServer() == null) {
m_message = new p(); m_message = new p();
m_message.addElement(new strong("Server not found: ")); m_message.addElement(new strong("Server not found: "));
m_message.addElement(serverID); m_message.addElement(serverID);
@ -317,7 +316,7 @@ public class AdempiereMonitor extends HttpServlet
ok = m_serverMgr.start(serverID); ok = m_serverMgr.start(serverID);
else else
ok = m_serverMgr.stop(serverID); ok = m_serverMgr.stop(serverID);
m_message.addElement(server.getName()); m_message.addElement(server.getServer().getName());
} }
} }
} }
@ -622,13 +621,13 @@ public class AdempiereMonitor extends HttpServlet
// ***** Server Links ***** // ***** Server Links *****
bb.addElement(new hr()); bb.addElement(new hr());
para = new p(); para = new p();
AdempiereServer[] servers = m_serverMgr.getAll(); ServerWrapper[] servers = m_serverMgr.getAll();
for (int i = 0; i < servers.length; i++) for (int i = 0; i < servers.length; i++)
{ {
if (i > 0) if (i > 0)
para.addElement(new br()); para.addElement(new br());
AdempiereServer server = servers[i]; ServerWrapper server = servers[i];
link = new a ("#" + server.getServerID(), server.getName()); link = new a ("#" + server.getServer().getServerID(), server.getServer().getName());
para.addElement(link); para.addElement(link);
font status = null; font status = null;
if (server.isAlive()) if (server.isAlive())
@ -646,10 +645,10 @@ public class AdempiereMonitor extends HttpServlet
bb.removeEndEndModifier(); bb.removeEndEndModifier();
for (int i = 0; i < servers.length; i++) for (int i = 0; i < servers.length; i++)
{ {
AdempiereServer server = servers[i]; ServerWrapper server = servers[i];
bb.addElement(new hr()); bb.addElement(new hr());
bb.addElement(new a().setName(server.getServerID())); bb.addElement(new a().setName(server.getServer().getServerID()));
bb.addElement(new h2(server.getName())); bb.addElement(new h2(server.getServer().getName()));
// //
table = new table(); table = new table();
table.setBorder(1); table.setBorder(1);
@ -660,10 +659,8 @@ public class AdempiereMonitor extends HttpServlet
if (server.isAlive()) if (server.isAlive())
{ {
String msg = "Stop"; String msg = "Stop";
if (server.isInterrupted()) link = new a ("adempiereMonitor?Action=Stop_" + server.getServer().getServerID(), msg);
msg += " (Interrupted)"; if (server.getServer().isSleeping())
link = new a ("adempiereMonitor?Action=Stop_" + server.getServerID(), msg);
if (server.isSleeping())
{ {
line.addElement(new th().addElement("Sleeping")); line.addElement(new th().addElement("Sleeping"));
line.addElement(new td().addElement(link)); line.addElement(new td().addElement(link));
@ -676,47 +673,45 @@ public class AdempiereMonitor extends HttpServlet
table.addElement(line); table.addElement(line);
line = new tr(); line = new tr();
line.addElement(new th().addElement("Start - Elapsed")); line.addElement(new th().addElement("Start - Elapsed"));
line.addElement(new td().addElement(WebEnv.getCellContent(server.getStartTime()) line.addElement(new td().addElement(WebEnv.getCellContent(server.getServer().getStartTime())
+ " - " + TimeUtil.formatElapsed(server.getStartTime()))); + " - " + TimeUtil.formatElapsed(server.getServer().getStartTime())));
} }
else else
{ {
String msg = "Start"; String msg = "Start";
if (server.isInterrupted())
msg += " (Interrupted)";
line.addElement(new th().addElement("Not Started")); line.addElement(new th().addElement("Not Started"));
link = new a ("adempiereMonitor?Action=Start_" + server.getServerID(), msg); link = new a ("adempiereMonitor?Action=Start_" + server.getServer().getServerID(), msg);
line.addElement(new td().addElement(link)); line.addElement(new td().addElement(link));
} }
table.addElement(line); table.addElement(line);
// //
line = new tr(); line = new tr();
line.addElement(new th().addElement("Description")); line.addElement(new th().addElement("Description"));
line.addElement(new td().addElement(WebEnv.getCellContent(server.getDescription()))); line.addElement(new td().addElement(WebEnv.getCellContent(server.getServer().getDescription())));
table.addElement(line); table.addElement(line);
// //
line = new tr(); line = new tr();
line.addElement(new th().addElement("Last Run")); line.addElement(new th().addElement("Last Run"));
line.addElement(new td().addElement(WebEnv.getCellContent(server.getDateLastRun()))); line.addElement(new td().addElement(WebEnv.getCellContent(server.getServer().getDateLastRun())));
table.addElement(line); table.addElement(line);
line = new tr(); line = new tr();
line.addElement(new th().addElement("Info")); line.addElement(new th().addElement("Info"));
line.addElement(new td().addElement(WebEnv.getCellContent(server.getServerInfo()))); line.addElement(new td().addElement(WebEnv.getCellContent(server.getServer().getServerInfo())));
table.addElement(line); table.addElement(line);
// //
line = new tr(); line = new tr();
line.addElement(new th().addElement("Next Run")); line.addElement(new th().addElement("Next Run"));
td td = new td(); td td = new td();
td.addElement(WebEnv.getCellContent(server.getDateNextRun(false))); td.addElement(WebEnv.getCellContent(server.getServer().getDateNextRun(false)));
td.addElement(" - "); td.addElement(" - ");
link = new a ("adempiereMonitor?RunNow=" + server.getServerID(), "(Run Now)"); link = new a ("adempiereMonitor?RunNow=" + server.getServer().getServerID(), "(Run Now)");
td.addElement(link); td.addElement(link);
line.addElement(td); line.addElement(td);
table.addElement(line); table.addElement(line);
// //
line = new tr(); line = new tr();
line.addElement(new th().addElement("Statistics")); line.addElement(new th().addElement("Statistics"));
line.addElement(new td().addElement(server.getStatistics())); line.addElement(new td().addElement(server.getServer().getStatistics()));
table.addElement(line); table.addElement(line);
// //
@ -725,7 +720,7 @@ public class AdempiereMonitor extends HttpServlet
link = new a ("#top", "Top"); link = new a ("#top", "Top");
bb.addElement(link); bb.addElement(link);
bb.addElement(" - "); bb.addElement(" - ");
link = new a ("adempiereMonitor?Log=" + server.getServerID(), "Log"); link = new a ("adempiereMonitor?Log=" + server.getServer().getServerID(), "Log");
bb.addElement(link); bb.addElement(link);
bb.addElement(" - "); bb.addElement(" - ");
link = new a ("adempiereMonitor", "Refresh"); link = new a ("adempiereMonitor", "Refresh");
@ -787,29 +782,29 @@ public class AdempiereMonitor extends HttpServlet
writer.print(m_serverMgr.getServerCount()); writer.print(m_serverMgr.getServerCount());
writer.println("</server-count>"); writer.println("</server-count>");
AdempiereServer[] servers = m_serverMgr.getAll(); ServerWrapper[] servers = m_serverMgr.getAll();
for (int i = 0; i < servers.length; i++) for (int i = 0; i < servers.length; i++)
{ {
AdempiereServer server = servers[i]; ServerWrapper server = servers[i];
writer.println("\t\t<server>"); writer.println("\t\t<server>");
writer.print("\t\t\t<id>"); writer.print("\t\t\t<id>");
writer.print(server.getServerID()); writer.print(server.getServer().getServerID());
writer.println("</id>"); writer.println("</id>");
writer.print("\t\t\t<name>"); writer.print("\t\t\t<name>");
writer.print(server.getName()); writer.print(server.getServer().getName());
writer.println("</name>"); writer.println("</name>");
writer.print("\t\t\t<description>"); writer.print("\t\t\t<description>");
writer.print(server.getDescription()); writer.print(server.getServer().getDescription());
writer.println("</description>"); writer.println("</description>");
writer.print("\t\t\t<info>"); writer.print("\t\t\t<info>");
writer.print(server.getServerInfo()); writer.print(server.getServer().getServerInfo());
writer.println("</info>"); writer.println("</info>");
writer.print("\t\t\t<status>"); writer.print("\t\t\t<status>");
if (server.isAlive()) if (server.isAlive())
{ {
if (server.isInterrupted()) if (server.isInterrupted())
writer.print("Interrupted"); writer.print("Interrupted");
else if (server.isSleeping()) else if (server.getServer().isSleeping())
writer.print("Sleeping"); writer.print("Sleeping");
else else
writer.print("Running"); writer.print("Running");
@ -818,16 +813,16 @@ public class AdempiereMonitor extends HttpServlet
writer.print("Stopped"); writer.print("Stopped");
writer.println("</status>"); writer.println("</status>");
writer.print("\t\t\t<start-time>"); writer.print("\t\t\t<start-time>");
writer.print(server.getStartTime()); writer.print(server.getServer().getStartTime());
writer.println("</start-time>"); writer.println("</start-time>");
writer.print("\t\t\t<last-run>"); writer.print("\t\t\t<last-run>");
writer.print(server.getDateLastRun()); writer.print(server.getServer().getDateLastRun());
writer.println("</last-run>"); writer.println("</last-run>");
writer.print("\t\t\t<next-run>"); writer.print("\t\t\t<next-run>");
writer.print(server.getDateNextRun(false)); writer.print(server.getServer().getDateNextRun(false));
writer.println("</next-run>"); writer.println("</next-run>");
writer.print("\t\t\t<statistics>"); writer.print("\t\t\t<statistics>");
writer.print(server.getStatistics()); writer.print(server.getServer().getStatistics());
writer.println("</statistics>"); writer.println("</statistics>");
writer.println("\t\t</server>"); writer.println("\t\t</server>");
} }

View File

@ -21,15 +21,12 @@ import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.util.ServerContext; import org.adempiere.util.ServerContext;
import org.adempiere.webui.AdempiereWebUI;
import org.adempiere.webui.desktop.IDesktop; import org.adempiere.webui.desktop.IDesktop;
import org.adempiere.webui.session.SessionContextListener; import org.adempiere.webui.session.SessionContextListener;
import org.adempiere.webui.util.ServerPushTemplate; import org.adempiere.webui.util.ServerPushTemplate;
import org.compiere.model.MSysConfig;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.zkoss.util.Locales; import org.zkoss.util.Locales;
import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.DesktopUnavailableException;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
/** /**
@ -44,7 +41,6 @@ public class DashboardRunnable implements Runnable, Serializable
private static final long serialVersionUID = 5995227773511788894L; private static final long serialVersionUID = 5995227773511788894L;
private Desktop desktop; private Desktop desktop;
private boolean stop = false;
private List<DashboardPanel> dashboardPanels; private List<DashboardPanel> dashboardPanels;
private IDesktop appDesktop; private IDesktop appDesktop;
private Locale locale; private Locale locale;
@ -72,77 +68,11 @@ public class DashboardRunnable implements Runnable, Serializable
public void run() public void run()
{ {
// default Update every one minutes
int interval = MSysConfig.getIntValue(MSysConfig.ZK_DASHBOARD_REFRESH_INTERVAL, 60000);
int cumulativeFailure = 0;
while(!stop) {
try {
Thread.sleep(interval);
} catch (InterruptedException e1) {
if (stop) break;
}
if (desktop.isAlive()) {
Locales.setThreadLocal(locale); Locales.setThreadLocal(locale);
try { try {
refreshDashboard(); refreshDashboard();
cumulativeFailure = 0;
} catch (DesktopUnavailableException de) {
cumulativeFailure++;
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.INFO, e.getLocalizedMessage(), (e.getCause() != null ? e.getCause() : e)); logger.log(Level.INFO, e.getLocalizedMessage(), (e.getCause() != null ? e.getCause() : e));
cumulativeFailure++;
}
if (cumulativeFailure > 3)
break;
} else {
logger.log(Level.INFO, "Desktop destroy, will kill session.");
killSession();
break;
}
}
}
private void killSession() {
if (desktop.getSession() != null && desktop.getSession().getNativeSession() != null)
{
//differentiate between real destroy and refresh
try
{
Thread.sleep(90000);
}
catch (InterruptedException e)
{
try
{
desktop.getSession().getAttributes().clear();
desktop.getSession().invalidate();
}
catch (Exception e1) {}
return;
}
try
{
Object sessionObj = desktop.getSession().getAttribute(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY);
if (sessionObj != null && sessionObj instanceof Desktop)
{
Desktop sessionDesktop = (Desktop) sessionObj;
//don't destroy session if it have been attached to another desktop ( refresh will do that )
if (sessionDesktop == desktop)
{
desktop.getSession().getAttributes().clear();
desktop.getSession().invalidate();
}
}
else
{
desktop.getSession().getAttributes().clear();
desktop.getSession().invalidate();
}
}
catch (Exception e1) {}
} }
} }
@ -184,10 +114,6 @@ public class DashboardRunnable implements Runnable, Serializable
} }
} }
public void stop() {
stop = true;
}
/** /**
* Add DashboardPanel to the auto refresh list * Add DashboardPanel to the auto refresh list
* @param dashboardPanel * @param dashboardPanel

View File

@ -23,6 +23,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.apps.AEnv;
@ -38,6 +40,7 @@ import org.adempiere.webui.report.HTMLExtension;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.FDialog;
import org.adempiere.webui.window.ZkReportViewerProvider; import org.adempiere.webui.window.ZkReportViewerProvider;
import org.compiere.Adempiere;
import org.compiere.model.I_AD_Menu; import org.compiere.model.I_AD_Menu;
import org.compiere.model.MDashboardContent; import org.compiere.model.MDashboardContent;
import org.compiere.model.MDashboardPreference; import org.compiere.model.MDashboardPreference;
@ -48,6 +51,7 @@ import org.compiere.model.MPInstancePara;
import org.compiere.model.MProcess; import org.compiere.model.MProcess;
import org.compiere.model.MQuery; import org.compiere.model.MQuery;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.print.ReportEngine; import org.compiere.print.ReportEngine;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
@ -91,8 +95,8 @@ public class DashboardController implements EventListener<Event> {
private List<Anchorchildren> columnList = new ArrayList<Anchorchildren>(); private List<Anchorchildren> columnList = new ArrayList<Anchorchildren>();
private Anchorlayout dashboardLayout; private Anchorlayout dashboardLayout;
private Anchorchildren maximizedHolder; private Anchorchildren maximizedHolder;
private Thread dashboardThread;
private DashboardRunnable dashboardRunnable; private DashboardRunnable dashboardRunnable;
private ScheduledFuture<?> dashboardFuture;
public DashboardController() { public DashboardController() {
dashboardLayout = new Anchorlayout(); dashboardLayout = new Anchorlayout();
@ -406,9 +410,9 @@ public class DashboardController implements EventListener<Event> {
{ {
dashboardRunnable.refreshDashboard(); dashboardRunnable.refreshDashboard();
dashboardThread = new Thread(dashboardRunnable, "UpdateInfo"); // default Update every one minutes
dashboardThread.setDaemon(true); int interval = MSysConfig.getIntValue(MSysConfig.ZK_DASHBOARD_REFRESH_INTERVAL, 60000);
dashboardThread.start(); dashboardFuture = Adempiere.getThreadPoolExecutor().scheduleWithFixedDelay(dashboardRunnable, interval, interval, TimeUnit.MILLISECONDS);
} }
} }
@ -620,15 +624,14 @@ public class DashboardController implements EventListener<Event> {
* @param appDesktop * @param appDesktop
*/ */
public void onSetPage(Page page, Desktop desktop, IDesktop appDesktop) { public void onSetPage(Page page, Desktop desktop, IDesktop appDesktop) {
if (dashboardThread != null && dashboardThread.isAlive()) { if (dashboardFuture != null && !dashboardFuture.isDone()) {
dashboardRunnable.stop(); dashboardFuture.cancel(true);
dashboardThread.interrupt();
DashboardRunnable tmp = dashboardRunnable; DashboardRunnable tmp = dashboardRunnable;
dashboardRunnable = new DashboardRunnable(tmp, desktop, appDesktop); dashboardRunnable = new DashboardRunnable(tmp, desktop, appDesktop);
dashboardThread = new Thread(dashboardRunnable, "UpdateInfo"); // default Update every one minutes
dashboardThread.setDaemon(true); int interval = MSysConfig.getIntValue(MSysConfig.ZK_DASHBOARD_REFRESH_INTERVAL, 60000);
dashboardThread.start(); dashboardFuture = Adempiere.getThreadPoolExecutor().scheduleWithFixedDelay(dashboardRunnable, interval, interval, TimeUnit.MILLISECONDS);
} }
} }
@ -636,9 +639,8 @@ public class DashboardController implements EventListener<Event> {
* clean up for logout * clean up for logout
*/ */
public void onLogOut() { public void onLogOut() {
if (dashboardThread != null && dashboardThread.isAlive()) { if (dashboardFuture != null && !dashboardFuture.isDone()) {
dashboardRunnable.stop(); dashboardFuture.cancel(true);
dashboardThread.interrupt();
} }
} }