List of usage examples for org.springframework.util StopWatch getTotalTimeSeconds
public double getTotalTimeSeconds()
From source file:com.quartzdesk.test.quartz.v1.AbstractJob.java
/** * The method invoked by the Spring scheduler. This method simply delegates the * execution to the {@link #executeJob(JobExecutionContext)} method. * * @param context a {@link JobExecutionContext} instance. * @throws JobExecutionException if an error occurs while executing the * job.//ww w. java 2 s . co m */ @SuppressWarnings("unchecked") @Override public final void execute(JobExecutionContext context) throws JobExecutionException { String jobFullName = context.getJobDetail().getFullName(); String triggerFullName = context.getTrigger().getFullName(); StopWatch sw = new StopWatch(); sw.start(); ClassLoader origContextClassLoader = Thread.currentThread().getContextClassLoader(); try { if (log.isInfoEnabled()) log.info("Started scheduled job: {}, fired by trigger: {}", jobFullName, triggerFullName); if (log.isDebugEnabled()) { StringBuilder jobDataMapDump = new StringBuilder(); // map that contains merged job data from the job detail data map and trigger data map JobDataMap jobDataMap = context.getMergedJobDataMap(); for (Iterator<String> keys = (Iterator<String>) jobDataMap.keySet().iterator(); keys.hasNext();) { String key = keys.next(); String value = CommonUtils.safeToString(jobDataMap.get(key)); jobDataMapDump.append(key).append('=').append(value); if (keys.hasNext()) jobDataMapDump.append(CommonConst.NL); } log.debug("Job data map dump:{}{}", CommonConst.NL, jobDataMapDump.toString()); } // Set the context class loader to be the class loader of the job class. // This is a workaround/fix for a problem with setting the thread's context // class loader through Quartz properties when WebSphere work manager threads // are used. Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); executeJob(context); sw.stop(); if (log.isInfoEnabled()) log.info("Finished scheduled job: {}. Time taken: {}s.", jobFullName, sw.getTotalTimeSeconds()); } catch (JobExecutionException e) { if (log.isErrorEnabled()) log.error("Error executing scheduled job: " + jobFullName, e); throw e; } finally { // restore the original thread context class loader Thread.currentThread().setContextClassLoader(origContextClassLoader); } }
From source file:com.persistent.cloudninja.scheduler.PerformanceMonitor.java
@Override public boolean execute() { StopWatch watch = new StopWatch(); try {//from w w w .j ava2s .c o m LOGGER.debug("PerformanceMonitor : Execute"); watch.start(); Date lastReadTime = kpiValueTempDao.getMaxTimestamp(); Date lastBatchTime = null; Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String date = null; if (lastReadTime == null) { date = dateFormat.format(calendar.getTime()); lastReadTime = dateFormat.parse(date); } calendar = Calendar.getInstance(); date = dateFormat.format(calendar.getTime()); Date currentUTCTime = dateFormat.parse(date); List<KpiValueTempEntity> listKpiValueTempEntities = null; while (lastReadTime.getTime() <= currentUTCTime.getTime()) { LOGGER.debug("PerformanceMonitor : Process performance counters"); calendar.setTime(lastReadTime); calendar.add(Calendar.MINUTE, 30); date = dateFormat.format(calendar.getTime()); lastBatchTime = dateFormat.parse(date); WADPerformanceCountersEntity[] arrPerfCounter = storageUtility .getPerfCounterEntities(lastReadTime.getTime(), lastBatchTime.getTime()); listKpiValueTempEntities = convertAzureEntityToDBEntity(arrPerfCounter); kpiValueTempDao.addAll(listKpiValueTempEntities); kpiValueTempDao.executeProcessKpiValues(); LOGGER.debug("PerformanceMonitor : Process complete"); lastReadTime = lastBatchTime; } watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "ProcessPerformanceCounters", ""); LOGGER.debug("PerformanceMonitor : Finish"); } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } return true; }
From source file:com.auditbucket.engine.service.MediationFacade.java
public Integer createHeaders(final Company company, final Fortress fortress, final List<MetaInputBean> inputBeans) throws DatagioException { fortress.setCompany(company);//w w w .j ava 2s .c om Long id = DateTime.now().getMillis(); StopWatch watch = new StopWatch(); watch.start(); logger.info("Starting Batch [{}] - size [{}]", id, inputBeans.size()); boolean newMode = true; if (newMode) { // Tune to balance against concurrency and batch transaction insert efficiency. List<List<MetaInputBean>> splitList = Lists.partition(inputBeans, 20); for (List<MetaInputBean> metaInputBeans : splitList) { class DLCommand implements Command { Iterable<MetaInputBean> headers = null; DLCommand(List<MetaInputBean> processList) { this.headers = new CopyOnWriteArrayList<>(processList); } @Override public Command execute() throws DatagioException { //fortressService.registerFortress(company, new FortressInputBean(headers.iterator().next().getFortress()), true); Iterable<TrackResultBean> resultBeans = trackService.createHeaders(headers, company, fortress); processLogs(company, resultBeans); return this; } } DeadlockRetry.execute(new DLCommand(metaInputBeans), "creating headers", 20); } } else { logger.info("Processing in slow Transaction mode"); for (MetaInputBean inputBean : inputBeans) { createHeader(company, fortress, inputBean); } } watch.stop(); logger.info("Completed Batch [{}] - secs= {}, RPS={}", id, f.format(watch.getTotalTimeSeconds()), f.format(inputBeans.size() / watch.getTotalTimeSeconds())); return inputBeans.size(); }
From source file:com.persistent.cloudninja.scheduler.TenantDBBandwidthProcessor.java
@Override public boolean execute() { boolean retVal = true; int tenantDBBWsCount = 0; try {/*ww w . ja va 2s. c om*/ LOGGER.debug("In Processor"); TenantDBBandwidthQueue queue = (TenantDBBandwidthQueue) getWorkQueue(); String message = queue.dequeue(SchedulerSettings.MessageVisibilityTimeout); if (message == null) { retVal = false; LOGGER.debug("Processor : msg is null"); } else { StopWatch watch = new StopWatch(); watch.start(); LOGGER.debug("Processor : msg is " + message); List<DBBandwidthUsageEntity> listDbBandwidthUsageEntities = partitionStatsAndBWUsageDao .getBandwidthUsage(); tenantDBBWsCount = listDbBandwidthUsageEntities.size(); Map<String, MeteringEntity> map = new HashMap<String, MeteringEntity>(); MeteringEntity meteringEntity = null; String dbName = null; String tenantId = null; for (DBBandwidthUsageEntity dbBandwidthUsageEntity : listDbBandwidthUsageEntities) { dbName = dbBandwidthUsageEntity.getDatabaseName(); if (dbName.startsWith("tnt_")) { tenantId = dbName.substring(4); if (map.containsKey(tenantId)) { meteringEntity = map.get(tenantId); setDatabaseBandwidth(dbBandwidthUsageEntity, meteringEntity); } else { meteringEntity = new MeteringEntity(); meteringEntity.setTenantId(tenantId); setDatabaseBandwidth(dbBandwidthUsageEntity, meteringEntity); map.put(tenantId, meteringEntity); } } } Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String date = dateFormat.format(calendar.getTime()); for (Iterator<MeteringEntity> iterator = map.values().iterator(); iterator.hasNext();) { meteringEntity = (MeteringEntity) iterator.next(); meteringEntity.setSnapshotTime(dateFormat.parse(date)); meteringDao.add(meteringEntity); } LOGGER.info("Processor : DB bandwidth calculated."); watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "ProcessMeteringTenantDBBandwidthUse", "Measured the database bandwith use for " + tenantDBBWsCount + " tenants."); } } catch (StorageException e) { retVal = false; LOGGER.error(e.getMessage(), e); } catch (ParseException e) { retVal = false; LOGGER.error(e.getMessage(), e); } return retVal; }
From source file:eu.databata.Propagator.java
public void init() { LOG.info(this.moduleName + " starting propagation (" + new Date() + ")"); StopWatch stopwatch = new StopWatch(); stopwatch.start();//from w ww . ja v a2 s . c o m if (isPropagatorDisabled()) { LOG.info("Changes propagation is disabled."); return; } // if (!simulationMode && !propagatorLock.lock()) { // return; // } while (!checkPreconditions()) { try { Thread.sleep(5000); } catch (InterruptedException e) { throw new RuntimeException(); } } try { collectStructureAndPropagate(); } finally { if (!simulationMode) { propagatorLock.unlock(); finished = true; } } LOG.info(this.moduleName + " finishing propagation (" + new Date() + ")," + " took " + Math.round(stopwatch.getTotalTimeSeconds()) + " seconds overall."); }
From source file:org.flockdata.integration.FileProcessor.java
public int endProcess(StopWatch watch, int rows, int ignoreCount) { watch.stop();/*from w w w. j av a 2s . c om*/ double mins = watch.getTotalTimeSeconds() / 60; long rowsProcessed = rows - skipCount; if (skipCount > 0) logger.info( "Completed [{}] rows in [{}] secs. rpm [{}]. Skipped first [{}] rows, finished on row {}, ignored [{}] rows", rowsProcessed, formatter.format(watch.getTotalTimeSeconds()), formatter.format(rowsProcessed / mins), skipCount, rows, ignoreCount); else logger.info("Completed [{}] rows in [{}] secs. rpm [{}] Finished on row [{}], ignored [{}] rows.", rowsProcessed, formatter.format(watch.getTotalTimeSeconds()), formatter.format(rowsProcessed / mins), rows, ignoreCount); return rows; }
From source file:org.kuali.kfs.gl.batch.PreScrubberStep.java
@Override protected CustomBatchExecutor getCustomBatchExecutor() { return new CustomBatchExecutor() { public boolean execute() { StopWatch stopWatch = new StopWatch(); stopWatch.start();//from www. ja va 2 s. com String inputFile = batchFileDirectoryName + File.separator + GeneralLedgerConstants.BatchFileSystem.BACKUP_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION; String outputFile = batchFileDirectoryName + File.separator + GeneralLedgerConstants.BatchFileSystem.PRE_SCRUBBER_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION; PreScrubberReportData preScrubberReportData = null; LineIterator oeIterator = null; try { oeIterator = FileUtils.lineIterator(new File(inputFile)); preScrubberReportData = preScrubberService.preprocessOriginEntries(oeIterator, outputFile); } catch (IOException e) { LOG.error("IO exception occurred during pre scrubbing.", e); throw new RuntimeException("IO exception occurred during pre scrubbing.", e); } finally { LineIterator.closeQuietly(oeIterator); } if (preScrubberReportData != null) { new PreScrubberReport().generateReport(preScrubberReportData, preScrubberReportWriterService); } stopWatch.stop(); if (LOG.isDebugEnabled()) { LOG.debug("scrubber step of took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete"); } return true; } }; }
From source file:org.kuali.kfs.module.ld.batch.LaborPreScrubberStep.java
/** * @see org.kuali.kfs.sys.batch.AbstractWrappedBatchStep#getCustomBatchExecutor() *///from w ww . ja v a 2 s . c om @Override protected CustomBatchExecutor getCustomBatchExecutor() { return new CustomBatchExecutor() { /** * @see org.kuali.kfs.sys.batch.service.WrappedBatchExecutorService.CustomBatchExecutor#execute() */ public boolean execute() { StopWatch stopWatch = new StopWatch(); stopWatch.start(); String inputFile = batchFileDirectoryName + File.separator + LaborConstants.BatchFileSystem.BACKUP_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION; String outputFile = batchFileDirectoryName + File.separator + LaborConstants.BatchFileSystem.PRE_SCRUBBER_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION; PreScrubberReportData preScrubberReportData = null; LineIterator oeIterator = null; try { oeIterator = FileUtils.lineIterator(new File(inputFile)); preScrubberReportData = laborPreScrubberService.preprocessOriginEntries(oeIterator, outputFile); } catch (IOException e) { LOG.error("IO exception occurred during pre scrubbing.", e); throw new RuntimeException("IO exception occurred during pre scrubbing.", e); } finally { LineIterator.closeQuietly(oeIterator); } if (preScrubberReportData != null) { ((WrappingBatchService) laborPreScrubberReportWriterService).initialize(); new PreScrubberReport().generateReport(preScrubberReportData, laborPreScrubberReportWriterService); ((WrappingBatchService) laborPreScrubberReportWriterService).destroy(); } stopWatch.stop(); if (LOG.isDebugEnabled()) { LOG.debug("labor pre-scrubber scrubber step took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete"); } return true; } }; }
From source file:org.kuali.kfs.sys.batch.Job.java
public static boolean runStep(ParameterService parameterService, String jobName, int currentStepNumber, Step step, Date jobRunDate) throws InterruptedException, WorkflowException { boolean continueJob = true; if (GlobalVariables.getUserSession() == null) { LOG.info(new StringBuffer("Started processing step: ").append(currentStepNumber).append("=") .append(step.getName()).append(" for user <unknown>")); } else {//from ww w . j a va 2 s . c om LOG.info(new StringBuffer("Started processing step: ").append(currentStepNumber).append("=") .append(step.getName()).append(" for user ") .append(GlobalVariables.getUserSession().getPrincipalName())); } if (!skipStep(parameterService, step, jobRunDate)) { Step unProxiedStep = (Step) ProxyUtils.getTargetIfProxied(step); Class<?> stepClass = unProxiedStep.getClass(); GlobalVariables.clear(); String stepUserName = KFSConstants.SYSTEM_USER; if (parameterService.parameterExists(stepClass, STEP_USER_PARM_NM)) { stepUserName = parameterService.getParameterValueAsString(stepClass, STEP_USER_PARM_NM); } if (LOG.isInfoEnabled()) { LOG.info(new StringBuffer("Creating user session for step: ").append(step.getName()).append("=") .append(stepUserName)); } GlobalVariables.setUserSession(new UserSession(stepUserName)); if (LOG.isInfoEnabled()) { LOG.info(new StringBuffer("Executing step: ").append(step.getName()).append("=").append(stepClass)); } StopWatch stopWatch = new StopWatch(); stopWatch.start(jobName); try { continueJob = step.execute(jobName, jobRunDate); } catch (InterruptedException e) { LOG.error("Exception occured executing step", e); throw e; } catch (RuntimeException e) { LOG.error("Exception occured executing step", e); throw e; } stopWatch.stop(); LOG.info(new StringBuffer("Step ").append(step.getName()).append(" of ").append(jobName) .append(" took ").append(stopWatch.getTotalTimeSeconds() / 60.0).append(" minutes to complete") .toString()); if (!continueJob) { LOG.info("Stopping job after successful step execution"); } } LOG.info(new StringBuffer("Finished processing step ").append(currentStepNumber).append(": ") .append(step.getName())); return continueJob; }
From source file:org.kuali.ole.sys.batch.Job.java
public static boolean runStep(ParameterService parameterService, String jobName, int currentStepNumber, Step step, Date jobRunDate) throws InterruptedException, WorkflowException { boolean continueJob = true; if (GlobalVariables.getUserSession() == null) { LOG.info(new StringBuffer("Started processing step: ").append(currentStepNumber).append("=") .append(step.getName()).append(" for user <unknown>")); } else {//from w ww .j a va2 s.c o m LOG.info(new StringBuffer("Started processing step: ").append(currentStepNumber).append("=") .append(step.getName()).append(" for user ") .append(GlobalVariables.getUserSession().getPrincipalName())); } if (!skipStep(parameterService, step, jobRunDate)) { Step unProxiedStep = (Step) ProxyUtils.getTargetIfProxied(step); Class<?> stepClass = unProxiedStep.getClass(); GlobalVariables.clear(); String stepUserName = getOleSelectDocumentService() .getSelectParameterValue(org.kuali.ole.sys.OLEConstants.SYSTEM_USER); if (parameterService.parameterExists(stepClass, STEP_USER_PARM_NM)) { stepUserName = parameterService.getParameterValueAsString(stepClass, STEP_USER_PARM_NM); } if (LOG.isInfoEnabled()) { LOG.info(new StringBuffer("Creating user session for step: ").append(step.getName()).append("=") .append(stepUserName)); } GlobalVariables.setUserSession(new UserSession(stepUserName)); if (LOG.isInfoEnabled()) { LOG.info(new StringBuffer("Executing step: ").append(step.getName()).append("=").append(stepClass)); } StopWatch stopWatch = new StopWatch(); stopWatch.start(jobName); try { continueJob = step.execute(jobName, jobRunDate); } catch (InterruptedException e) { LOG.error("Exception occured executing step", e); throw e; } catch (RuntimeException e) { LOG.error("Exception occured executing step", e); throw e; } stopWatch.stop(); LOG.info(new StringBuffer("Step ").append(step.getName()).append(" of ").append(jobName) .append(" took ").append(stopWatch.getTotalTimeSeconds() / 60.0).append(" minutes to complete") .toString()); if (!continueJob) { LOG.info("Stopping job after successful step execution"); } } LOG.info(new StringBuffer("Finished processing step ").append(currentStepNumber).append(": ") .append(step.getName())); return continueJob; }