List of usage examples for java.util.concurrent ExecutorService execute
void execute(Runnable command);
From source file:com.chicm.cmraft.core.NodeConnectionManager.java
private void appendEntries(long term, ServerInfo leaderId, long leaderCommit, long prevLogIndex, long prevLogTerm, List<RaftLogEntry> entries, long maxIndex) { Preconditions.checkNotNull(entries); int nServers = getRemoteServers().size(); if (nServers <= 0) { return;//from w w w. j a va 2 s . com } ExecutorService executor = Executors.newFixedThreadPool(nServers, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(getRaftNode().getName() + "-AsyncRpcCaller" + (byte) System.currentTimeMillis()); return t; } }); for (ServerInfo server : getRemoteServers()) { NodeConnection connection = connections.get(server); LOG.debug(getRaftNode().getName() + ": SENDING appendEntries Request TO: " + server); Thread t = new Thread(new AsynchronousAppendEntriesWorker(getRaftNode(), connection, getRaftNode().getRaftLog(), getRaftNode().getServerInfo(), term, leaderCommit, prevLogIndex, prevLogTerm, entries, maxIndex)); t.setDaemon(true); executor.execute(t); } }
From source file:com.uwsoft.editor.data.manager.DataManager.java
public void importExternalImagesIntoProject(final ArrayList<File> files, ProgressHandler progressHandler) { handler = progressHandler;/*from w w w. ja va 2 s .c o m*/ currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { copyImageFilesForAllResolutionsIntoProject(files, true); resolutionManager.rePackProjectImagesForAllResolutions(); } }); executor.execute(new Runnable() { @Override public void run() { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); } }); executor.shutdown(); }
From source file:com.adaptris.core.PoolingWorkflow.java
private void populatePool() throws CoreException { int size = minIdle(); ExecutorService populator = Executors.newCachedThreadPool(); try {// w w w .j av a 2 s . c o m final CyclicBarrier barrier = new CyclicBarrier(size + 1); log.trace("Need more ({}) children as soon as possible to handle work. Get to it", size); final List<Worker> workers = new ArrayList<>(size); for (int i = 0; i < size; i++) { populator.execute(new Runnable() { @Override public void run() { try { Worker w = objectPool.borrowObject(); workers.add(w); barrier.await(initWaitTimeMs(), TimeUnit.MILLISECONDS); } catch (Exception e) { barrier.reset(); } } }); } barrier.await(initWaitTimeMs(), TimeUnit.MILLISECONDS); for (Worker worker : workers) { objectPool.returnObject(worker); } } catch (Exception e) { throw new CoreException(e); } finally { populator.shutdownNow(); } }
From source file:com.uwsoft.editor.data.manager.DataManager.java
public void importExternalSpineAnimationsIntoProject(final ArrayList<File> files, ProgressHandler progressHandler) { handler = progressHandler;// w w w. ja v a 2s . c o m currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { for (File file : files) { File copiedFile = importExternalAnimationIntoProject(file); if (copiedFile.getName().toLowerCase().endsWith(".atlas")) { resolutionManager.resizeSpineAnimationForAllResolutions(copiedFile, currentProjectInfoVO); } else if (copiedFile.getName().toLowerCase().endsWith(".scml")) { //resizeSpriterAnimationForAllResolutions(copiedFile, currentProjectInfoVO); } } } }); executor.execute(new Runnable() { @Override public void run() { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); } }); executor.shutdown(); }
From source file:com.uwsoft.editor.data.manager.DataManager.java
public void importExternalParticlesIntoProject(final ArrayList<File> files, ProgressHandler progressHandler) { final String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/particles"; handler = progressHandler;//ww w. ja v a2 s. c om currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { for (File file : files) { if (file.isFile() && file.exists()) { try { //copy images ArrayList<File> imgs = getImageListFromAtlas(file); copyImageFilesForAllResolutionsIntoProject(imgs, false); // copy the file String newName = file.getName(); File target = new File(targetPath + "/" + newName); FileUtils.copyFile(file, target); } catch (Exception e) { e.printStackTrace(); System.out.println("Error importing particles"); //showError("Error importing particles \n Particle Atals not found \n Please place particle atlas and particle effect file in the same directory "); } } } resolutionManager.rePackProjectImagesForAllResolutions(); } }); executor.execute(new Runnable() { @Override public void run() { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); } }); executor.shutdown(); }
From source file:com.uwsoft.editor.data.manager.DataManager.java
public void importExternalFontIntoProject(ArrayList<File> externalfiles, ProgressHandler progressHandler) { String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/freetypefonts"; TffFilenameFilter ttfFilenameFilter = new TffFilenameFilter(); handler = progressHandler;/*from ww w . java2 s . c om*/ float perCopyPercent = 95.0f / externalfiles.size(); for (File file : externalfiles) { if (!ttfFilenameFilter.accept(null, file.getName())) { continue; } try { File target = new File(targetPath); if (!target.exists()) { File newFile = new File(targetPath); newFile.mkdir(); } File fileTarget = new File(targetPath + "/" + file.getName()); FileUtils.copyFile(file, fileTarget); } catch (IOException e) { e.printStackTrace(); } System.out.println(perCopyPercent); changePercentBy(perCopyPercent); ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); } }); executor.shutdown(); } }
From source file:com.uwsoft.editor.data.manager.DataManager.java
public void importExternalStyleIntoProject(final File file, ProgressHandler progressHandler) { final String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/styles"; FileHandle fileHandle = Gdx.files.absolute(file.getAbsolutePath()); final MySkin skin = new MySkin(fileHandle); handler = progressHandler;/* www. ja v a 2 s . c o m*/ currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { for (int i = 0; i < skin.fontFiles.size(); i++) { File copyFontFile = new File(file.getParentFile(), skin.fontFiles.get(i) + ".fnt"); File copyImageFile = new File(file.getParentFile(), skin.fontFiles.get(i) + ".png"); if (file.isFile() && file.exists() && copyFontFile.isFile() && copyFontFile.exists() && copyImageFile.isFile() && copyImageFile.exists()) { File fileTarget = new File(targetPath + "/" + file.getName()); File fontTarget = new File(targetPath + "/" + copyFontFile.getName()); File imageTarget = new File(targetPath + "/" + copyImageFile.getName()); try { FileUtils.copyFile(file, fileTarget); FileUtils.copyFile(copyFontFile, fontTarget); FileUtils.copyFile(copyImageFile, imageTarget); } catch (IOException e) { // TODO Auto-generated catch block System.err.println(e.getMessage()); e.printStackTrace(); } } else { System.err.println("SOME FILES ARE MISSING"); } } } }); executor.execute(new Runnable() { @Override public void run() { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); } }); executor.shutdown(); }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
public void importAtlasesIntoProject(final Array<FileHandle> files, ProgressHandler progressHandler) { handler = progressHandler;//from w w w. j a va 2s . co m currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { for (FileHandle fileHandle : files) { // TODO: logic goes here } }); executor.execute(() -> { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); }); executor.shutdown(); }
From source file:com.arpnetworking.metrics.impl.ApacheHttpSink.java
ApacheHttpSink(final Builder builder, final Supplier<CloseableHttpClient> httpClientSupplier, final org.slf4j.Logger logger) { _uri = builder._uri;/* w w w.ja v a 2s. co m*/ _bufferSize = builder._bufferSize; _maxBatchSize = builder._maxBatchSize; _emptyQueueInterval = builder._emptyQueueInterval; _eventHandler = Optional.ofNullable(builder._eventHandler); _eventsDroppedLogger = new RateLimitedLogger("EventsDroppedLogger", logger, builder._eventsDroppedLoggingInterval); final ExecutorService executor = Executors.newFixedThreadPool(builder._parallelism, runnable -> new Thread(runnable, "MetricsSinkApacheHttpWorker")); Runtime.getRuntime().addShutdownHook(new ShutdownHookThread(this._isRunning, executor)); // Use a single shared worker instance across the pool; see getSharedHttpClient final HttpDispatch httpDispatchWorker = new HttpDispatch(httpClientSupplier, builder._eventsDroppedLoggingInterval, logger, _eventHandler); for (int i = 0; i < builder._parallelism; ++i) { executor.execute(httpDispatchWorker); } }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
public void importImagesIntoProject(final Array<FileHandle> files, ProgressHandler progressHandler) { if (files == null) { return;//w w w . j a v a 2 s. c o m } handler = progressHandler; currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { copyImageFilesForAllResolutionsIntoProject(files, true); ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME); resolutionManager.rePackProjectImagesForAllResolutions(); }); executor.execute(() -> { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); }); executor.shutdown(); }