List of usage examples for java.util.concurrent TimeUnit MINUTES
TimeUnit MINUTES
To view the source code for java.util.concurrent TimeUnit MINUTES.
Click Source Link
From source file:net.openhft.chronicle.logger.logback.LogbackVanillaChroniclePerfTest.java
@Test public void testMultiThreadLogging() throws IOException, InterruptedException { warmup(LoggerFactory.getLogger("perf-binary-vanilla-chronicle")); warmup(LoggerFactory.getLogger("perf-plain-vanilla")); final int THREADS = Runtime.getRuntime().availableProcessors(); for (int size : new int[] { 64, 128, 256 }) { {/*from ww w . j a v a 2 s . c om*/ final int RUNS = 250000; final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-binary-vanilla-chronicle")); } es.shutdown(); es.awaitTermination(2, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "ChronicleLog.MT (runs=%d, min size=%03d, elapsed=%.3f ms) took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } { final int RUNS = 10000; final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-plain-vanilla")); } es.shutdown(); es.awaitTermination(5, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "Plain.MT (runs=%d, min size=%03d, elapsed=%.3f ms)): took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } } IOTools.deleteDir(basePath("perf-binary-vanilla-chronicle")); }
From source file:net.openhft.chronicle.logger.log4j2.Log4j2VanillaChroniclePerfTest.java
@Test public void testMultiThreadLogging() throws IOException, InterruptedException { warmup(LoggerFactory.getLogger("perf-binary-vanilla-chronicle")); warmup(LoggerFactory.getLogger("perf-plain-vanilla")); final int RUNS = 250000; // ~10s final int THREADS = Runtime.getRuntime().availableProcessors(); for (int size : new int[] { 64, 128, 256 }) { {//from w w w . j a va2s . c o m final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-binary-vanilla-chronicle")); } es.shutdown(); es.awaitTermination(2, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "ChronicleLog.MT (runs=%d, min size=%03d, elapsed=%.3f ms) took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } { final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-plain-vanilla")); } es.shutdown(); es.awaitTermination(10, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "Plain.MT (runs=%d, min size=%03d, elapsed=%.3f ms)): took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } } IOTools.deleteDir(basePath("perf-binary-vanilla-chronicle")); }
From source file:com.couchbase.client.java.util.CouchbaseTestContext.java
/** * If N1QL is available (detected or forced), this method will attempt to create a PRIMARY INDEX on the bucket. * It will ignore an already existing primary index. If other N1QL errors arise, a {@link CouchbaseException} will * be thrown (with the message containing the list of errors). *//*from www . java 2s . co m*/ public CouchbaseTestContext ensurePrimaryIndex() { //test for N1QL if (clusterManager.info().checkAvailable(CouchbaseFeature.N1QL)) { N1qlQueryResult result = bucket() .query(N1qlQuery.simple("CREATE PRIMARY INDEX ON `" + bucketName() + "`", N1qlParams.build().consistency(ScanConsistency.REQUEST_PLUS)), 2, TimeUnit.MINUTES); if (!result.finalSuccess()) { //ignore "index already exist" for (JsonObject error : result.errors()) { if (!error.getString("msg").contains("already exist")) { throw new CouchbaseException( "Could not CREATE PRIMARY INDEX - " + result.errors().toString()); } } } } return this; }
From source file:gov.ca.cwds.cals.service.ComplaintsService.java
@SuppressWarnings("squid:S2142") //Logging and informing client instead of shutdown private void shutdownExecutionService(ExecutorService executorService) { executorService.shutdown();/*w w w . ja va 2s . c o m*/ try { if (!executorService.awaitTermination(1, TimeUnit.MINUTES)) { executorService.shutdownNow(); } } catch (InterruptedException e) { String message = "Can't properly shutdown complaints execution pool"; LOGGER.warn(message, e); throw new ServiceException(message, e); } }
From source file:com.streamsets.datacollector.antennadoctor.storage.AntennaDoctorStorage.java
@Override protected void initTask() { LOG.info("Repository location: {}", repositoryDirectory); try {// w w w . j av a2 s.c o m // Make sure that we have our own directory to operate in if (!Files.exists(repositoryDirectory)) { Files.createDirectories(repositoryDirectory); } Path store = repositoryDirectory.resolve(AntennaDoctorConstants.FILE_DATABASE); if (!Files.exists(store)) { try (OutputStream stream = Files.newOutputStream(store)) { Resources.copy( Resources.getResource(AntennaDoctorStorage.class, AntennaDoctorConstants.FILE_DATABASE), stream); } } } catch (IOException e) { LOG.error("Cant initialize repository: {}", e.getMessage(), e); return; } // Schedule override runnable if allowed in configuration if (configuration.get(AntennaDoctorConstants.CONF_OVERRIDE_ENABLE, AntennaDoctorConstants.DEFAULT_OVERRIDE_ENABLE)) { LOG.info("Enabling polling of {} to override the rule database", AntennaDoctorConstants.FILE_OVERRIDE); this.executorService = Executors.newSingleThreadExecutor(); this.overrideRunnable = new OverrideFileRunnable(); this.future = executorService.submit(this.overrideRunnable); } // Remote repo handling if (configuration.get(AntennaDoctorConstants.CONF_UPDATE_ENABLE, AntennaDoctorConstants.DEFAULT_UPDATE_ENABLE)) { if (overrideRunnable != null) { LOG.info("Using override, not starting update thread."); } else { this.executorService = Executors.newSingleThreadScheduledExecutor(); this.updateRunnable = new UpdateRunnable(); this.future = ((ScheduledExecutorService) executorService).scheduleAtFixedRate(updateRunnable, configuration.get(AntennaDoctorConstants.CONF_UPDATE_DELAY, AntennaDoctorConstants.DEFAULT_UPDATE_DELAY), configuration.get(AntennaDoctorConstants.CONF_UPDATE_PERIOD, AntennaDoctorConstants.DEFAULT_UPDATE_PERIOD), TimeUnit.MINUTES); } } // And finally load rules delegate.loadNewRules(loadRules()); }
From source file:com.cloud.agent.Agent.java
public Agent(final IAgentShell shell) { _shell = shell;/*from w w w . j av a 2 s .c om*/ _link = null; _connection = new NioClient("Agent", _shell.getHost(), _shell.getPort(), _shell.getWorkers(), this); Runtime.getRuntime().addShutdownHook(new ShutdownThread(this)); _ugentTaskPool = new ThreadPoolExecutor(shell.getPingRetries(), 2 * shell.getPingRetries(), 10, TimeUnit.MINUTES, new SynchronousQueue<Runnable>(), new NamedThreadFactory("UgentTask")); _executor = new ThreadPoolExecutor(_shell.getWorkers(), 5 * _shell.getWorkers(), 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("agentRequest-Handler")); }
From source file:nl.esciencecenter.octopus.webservice.job.OctopusManager.java
/** * Submit a job request./*from ww w.ja v a2 s . c o m*/ * * @param request The job request * @param httpClient http client used to reporting status to job callback. * @return SandboxedJob job * * @throws OctopusIOException * @throws OctopusException * @throws URISyntaxException */ public SandboxedJob submitJob(JobSubmitRequest request, HttpClient httpClient) throws OctopusIOException, OctopusException, URISyntaxException { Credential credential = configuration.getCredential(); // filesystems cant have path in them so strip eg. file:///tmp to file:/// URI s = configuration.getSandboxRoot(); URI sandboxURI = new URI(s.getScheme(), s.getUserInfo(), s.getHost(), s.getPort(), "/", s.getQuery(), s.getFragment()); //create sandbox FileSystem sandboxFS = octopus.files().newFileSystem(sandboxURI, credential, null); String sandboxRoot = configuration.getSandboxRoot().getPath(); AbsolutePath sandboxRootPath = octopus.files().newPath(sandboxFS, new RelativePath(sandboxRoot)); Sandbox sandbox = request.toSandbox(octopus, sandboxRootPath, null); // create job description JobDescription description = request.toJobDescription(); description.setQueueName(configuration.getQueue()); description.setWorkingDirectory(sandbox.getPath().getPath()); long cancelTimeout = configuration.getPollConfiguration().getCancelTimeout(); // CancelTimeout is in milliseconds and MaxTime must be in minutes, so convert it int maxTime = (int) TimeUnit.MINUTES.convert(cancelTimeout, TimeUnit.MILLISECONDS); description.setMaxTime(maxTime); // stage input files sandbox.upload(); // submit job Job job = octopus.jobs().submitJob(scheduler, description); // store job in jobs map SandboxedJob sjob = new SandboxedJob(sandbox, job, request, httpClient); jobs.put(sjob.getIdentifier(), sjob); // JobsPoller will poll job status and download sandbox when job is done. return sjob; }
From source file:no.uis.fsws.proxy.StudinfoProxyImpl.java
@Override @SneakyThrows//from w w w. j ava2 s .c om public List<Kurs> getKurs(final XMLGregorianCalendar arstall, final Terminkode terminkode, final Sprakkode sprak, final int institusjonsnr, Integer fakultetsnr, Integer instituttnr, Integer gruppenr) { final StudInfoImport svc = getServiceForPrincipal(); Future<List<Kurs>> future = executor.submit(new Callable<List<Kurs>>() { @Override public List<Kurs> call() throws Exception { final FsStudieinfo sinfo = svc.fetchCourses(institusjonsnr, arstall.getYear(), terminkode.toString(), sprak.toString()); return sinfo.getKurs(); } }); return future.get(timeoutMinutes, TimeUnit.MINUTES); }
From source file:builder.smartfrog.SmartFrogAction.java
public void interrupt() { String[] cl = builder.buildStopDaemonCommandLine(host); logUpstream("[SmartFrog] INFO: Trying to interrupt daemon on host " + host); logUpstream("[SmartFrog] INFO: Interrupt command is " + Functions.cmdArrayToString(cl)); try {//from w w w. j a v a 2 s. c o m //TODO possible concurrent writing into log (from interrupt() as well as from run())!! (however synchronization could lead to livelock) Proc killProc = launcher.launch().cmds(cl).envs(build.getEnvironment(log)).pwd(build.getWorkspace()) .stdout(log).start(); int exitCode = killProc.joinWithTimeout(5, TimeUnit.MINUTES, console.getListener()); if (exitCode != 0) { // something went wrong, let's try hard kill, also with timeout as whole machine can be unresponsive // TODO replace with something more sophisticated/universal than bash script String[] cmd = builder.buildKilleThemAllCommandLine(host); Proc killThemAll = launcher.launch().cmds(cmd).envs(build.getEnvironment(log)) .pwd(build.getWorkspace()).stdout(log).start(); // still can take some time if e.g. server is under heavy load due to deadlock or something like this, so let wait few minutes too exitCode = killProc.joinWithTimeout(3, TimeUnit.MINUTES, console.getListener()); if (exitCode != 0 && killThemAll.isAlive()) { logUpstream( "[SmartFrog] ERROR: Hard kill timeout, giving up. Machine is probably unresponsive, plase check it manually."); } } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:nl.esciencecenter.osmium.job.XenonManager.java
/** * Submit a job request./* w ww. ja v a2 s . c o m*/ * * @param request * The job request * @param httpClient * http client used to reporting status to job callback. * @return SandboxedJob job * * @throws XenonException If staging file or submit job failed */ public SandboxedJob submitJob(JobSubmitRequest request, HttpClient httpClient) throws XenonException { Sandbox sandbox = request.toSandbox(xenon.files(), sandboxRootPath, null); // create job description JobDescription description = request.toJobDescription(); description.setQueueName(configuration.getScheduler().getQueue()); description.setWorkingDirectory(sandbox.getPath().getRelativePath().getAbsolutePath()); long cancelTimeout = configuration.getPoll().getCancelTimeout(); // CancelTimeout is in milliseconds and MaxTime must be in minutes, so convert it int maxTime = (int) TimeUnit.MINUTES.convert(cancelTimeout, TimeUnit.MILLISECONDS); description.setMaxTime(maxTime); // stage input files sandbox.upload(); // submit job Job job = xenon.jobs().submitJob(scheduler, description); // store job in jobs map SandboxedJob sjob = new SandboxedJob(sandbox, job, request, httpClient); jobs.put(sjob.getIdentifier(), sjob); // JobsPoller will poll job status and download sandbox when job is done. return sjob; }