List of usage examples for java.util.concurrent Executors newSingleThreadExecutor
public static ExecutorService newSingleThreadExecutor()
From source file:org.bitcoinrt.client.StubMtgoxClient.java
@Override public void start() { this.executor = Executors.newSingleThreadExecutor(); this.executor.submit(new Runnable() { @Override/*from w ww . j a v a 2 s . c om*/ public void run() { while (!shuttingDown) { String expression = "{\"channel\":\"dbf1dee9-4f2e-4a08-8cb7-748919a71b21\",\"op\":\"private\"," + "\"origin\":\"broadcast\",\"private\":\"trade\",\"trade\":{\"amount\":[%f]," + "\"date\":[%d],\"price\":12.239,\"exchange\":\"mtgoxUSD\"," + "\"price_currency\":\"USD\",\"primary\":\"Y\"," + "\"txid\":\"1348679989121772\",\"type\":\"trade\"}}"; long timestamp = (long) (Math.floor(new Date().getTime() / 1000)); double amount = Math.floor(Math.random() * 20); String message = String.format(expression, amount, timestamp); onMessage(message); try { Thread.sleep(7000); } catch (InterruptedException ex) { logger.debug("Stub MtGox service interrupted"); } } logger.debug("Stub MtGox service stopped"); } }); }
From source file:fr.smile.services.PatchService.java
private PatchService() { pool = Executors.newSingleThreadExecutor(); listVersion = new ArrayList<>(); listPatch = new ArrayList<>(); try {//w w w . j a v a 2 s. c o m readFile(); // Reading the file line by line } catch (IOException e) { LOGGER.error("", e); } }
From source file:com.microsoft.azure.servicebus.samples.queuesgettingstarted.QueuesGettingStarted.java
public void run(String connectionString) throws Exception { // Create a QueueClient instance for receiving using the connection string builder // We set the receive mode to "PeekLock", meaning the message is delivered // under a lock and must be acknowledged ("completed") to be removed from the queue QueueClient receiveClient = new QueueClient(new ConnectionStringBuilder(connectionString, "BasicQueue"), ReceiveMode.PEEKLOCK);//from ww w. j a v a2 s .c o m // We are using single thread executor as we are only processing one message at a time ExecutorService executorService = Executors.newSingleThreadExecutor(); this.registerReceiver(receiveClient, executorService); // Create a QueueClient instance for sending and then asynchronously send messages. // Close the sender once the send operation is complete. QueueClient sendClient = new QueueClient(new ConnectionStringBuilder(connectionString, "BasicQueue"), ReceiveMode.PEEKLOCK); this.sendMessagesAsync(sendClient).thenRunAsync(() -> sendClient.closeAsync()); // wait for ENTER or 10 seconds elapsing waitForEnter(10); // shut down receiver to close the receive loop receiveClient.close(); executorService.shutdown(); }
From source file:io.cloudslang.content.azure.services.AuthorizationTokenImpl.java
@NotNull public static AuthenticationResult getToken(@NotNull final AuthorizationTokenInputs inputs) throws Exception { final ExecutorService service = Executors.newSingleThreadExecutor(); final AuthenticationContext context = new AuthenticationContext(inputs.getAuthority(), false, service); context.setProxy(getProxy(inputs.getProxyHost(), inputs.getProxyPort(), inputs.getProxyUsername(), inputs.getProxyPassword())); final Future<AuthenticationResult> future = context.acquireToken(inputs.getResource(), inputs.getClientId(), inputs.getUsername(), inputs.getPassword(), null); service.shutdown();//from w ww.j a v a 2 s . c o m return future.get(); }
From source file:com.dickthedeployer.dick.web.service.util.OptymisticLockService.java
@Transactional public void shouldThrowOptymisticLockException(Long id) throws InterruptedException, ExecutionException, TimeoutException { Worker finalWorker = workerDao.findOne(id); Executors.newSingleThreadExecutor().submit(() -> { Worker theSameWorker = workerDao.findOne(finalWorker.getId()); theSameWorker.setStatus(Worker.Status.BUSY); workerDao.save(theSameWorker);/*from w w w.j a va 2s. c o m*/ }).get(1, TimeUnit.SECONDS); finalWorker.setStatus(Worker.Status.DEAD); workerDao.save(finalWorker); }
From source file:com.microsoft.azure.servicebus.samples.partitionedqueues.PartitionedQueues.java
public void run(String connectionString) throws Exception { QueueClient sendClient;// www. jav a 2s .c o m QueueClient receiveClient; // Create a QueueClient instance using the connection string builder // We set the receive mode to "PeekLock", meaning the message is delivered // under a lock and must be acknowledged ("completed") to be removed from the queue receiveClient = new QueueClient(new ConnectionStringBuilder(connectionString, "PartitionedQueue"), ReceiveMode.PEEKLOCK); // We are using single thread executor as we are only processing one message at a time ExecutorService executorService = Executors.newSingleThreadExecutor(); this.registerMessageHandler(receiveClient, executorService); sendClient = new QueueClient(new ConnectionStringBuilder(connectionString, "PartitionedQueue"), ReceiveMode.PEEKLOCK); this.sendMessagesAsync(sendClient).thenRunAsync(() -> sendClient.closeAsync()); // wait for ENTER or 10 seconds elapsing waitForEnter(10); receiveClient.close(); executorService.shutdown(); }
From source file:com.microsoft.azure.servicebus.samples.scheduledmessages.ScheduledMessages.java
public void run(String connectionString) throws Exception { QueueClient sendClient;//from w ww.j a v a2 s .c o m QueueClient receiveClient; // Create a QueueClient instance using the connection string builder // We set the receive mode to "PeekLock", meaning the message is delivered // under a lock and must be acknowledged ("completed") to be removed from the queue receiveClient = new QueueClient(new ConnectionStringBuilder(connectionString, "BasicQueue"), ReceiveMode.PEEKLOCK); // We are using single thread executor as we are only processing one message at a time ExecutorService executorService = Executors.newSingleThreadExecutor(); this.initializeReceiver(receiveClient, executorService); sendClient = new QueueClient(new ConnectionStringBuilder(connectionString, "BasicQueue"), ReceiveMode.PEEKLOCK); this.sendMessagesAsync(sendClient).thenRunAsync(() -> sendClient.closeAsync()); waitForEnter(150); receiveClient.close(); executorService.shutdown(); }
From source file:com.parse.GCMService.java
@Override public void onCreate() { executor = Executors.newSingleThreadExecutor(); }
From source file:es.deustotech.piramide.utils.tts.TextToSpeechWeb.java
private static ExecutorService createExecutor() { return Executors.newSingleThreadExecutor(); }
From source file:com.github.brandtg.switchboard.FileLogIndexer.java
/** * Creates an agent to index chunks of files. *///from w w w . j av a 2 s .com public FileLogIndexer(FileLogServerConfig config, LogIndex logIndex) throws IOException { this.config = config; this.executorService = Executors.newSingleThreadExecutor(); File rootDir = new File(config.getRootDir()); if (!rootDir.exists()) { FileUtils.forceMkdir(rootDir); LOG.info("Created {}", rootDir); } // Find the current high water mark index among all files in directory long indexHighWaterMark = 0; File[] files = rootDir.listFiles(); if (files != null) { for (File file : files) { LogRegion highWaterMark = logIndex.getHighWaterMark(file.getAbsolutePath()); if (highWaterMark != null && highWaterMark.getIndex() > indexHighWaterMark) { indexHighWaterMark = highWaterMark.getIndex(); } } } this.fileLogWatcher = new FileLogWatcher(config.getFilePrefix(), logIndex, indexHighWaterMark, config.getWaitSleepMillis(), config.getWaitTimeoutMillis()); }