Example usage for java.util.concurrent ExecutorService execute

List of usage examples for java.util.concurrent ExecutorService execute

Introduction

In this page you can find the example usage for java.util.concurrent ExecutorService execute.

Prototype

void execute(Runnable command);

Source Link

Document

Executes the given command at some time in the future.

Usage

From source file:de.dfki.iui.mmds.dialogue.SiamStateMachine.java

@Override
public boolean start() {
    isRunning = true;//from ww w  .  j av a  2 s. co m
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.execute(queueWorker);
    addListener(siamEvaluator);
    return super.start();
}

From source file:ubic.gemma.core.loader.util.fetcher.FtpFetcher.java

protected Collection<LocalFile> doTask(FutureTask<Boolean> future, long expectedSize, String seekFileName,
        String outputFileName) {// w  ww.  j  a v a  2  s .  c  o m

    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.execute(future);
    executor.shutdown();

    try {

        File outputFile = new File(outputFileName);
        boolean ok = waitForDownload(future, expectedSize, outputFile);

        if (!ok) {
            // cancelled, probably.
            log.info("Download failed, was it cancelled?");
            return null;
        } else if (future.get()) {
            if (log.isInfoEnabled())
                log.info("Done: local file is " + outputFile);
            LocalFile file = fetchedFile(seekFileName, outputFile.getAbsolutePath());
            Collection<LocalFile> result = new HashSet<>();
            result.add(file);
            return result;
        }
    } catch (ExecutionException e) {
        throw new RuntimeException("Couldn't fetch " + seekFileName, e);
    } catch (InterruptedException e) {
        log.warn("Interrupted: Couldn't fetch " + seekFileName, e);
        return null;
    } catch (CancellationException e) {
        log.info("Cancelled");
        return null;
    }
    throw new RuntimeException("Couldn't fetch file for " + seekFileName);
}

From source file:net.sf.appstatus.demo.batch.LaunchClassicBatchSampleServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    // launch the batch
    ExecutorService executorService = Executors.newCachedThreadPool();

    BatchSample batch = (BatchSample) WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext()).getBean("batch");
    executorService.execute(batch);

    BatchSample2 batch2 = (BatchSample2) WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext()).getBean("batch2");
    executorService.execute(batch2);/*  ww w  . j a v a2 s . c  o m*/

    ServletOutputStream os = resp.getOutputStream();

    os.write("<html><head".getBytes(ENCODING));
    os.write("<body>".getBytes(ENCODING));
    os.write("<h1>Ok</h1>".getBytes(ENCODING));
    os.write("</body></html>".getBytes(ENCODING));
}

From source file:org.spinsuite.util.SFAAsyncTask.java

/**
 * Run Method/* w  ww.j ava  2s .  com*/
 * @author <a href="mailto:carlosaparadam@gmail.com">Carlos Parada</a> 05/03/2014, 22:39:48
 * @param p_Class
 * @param p_Method
 * @param p_Params
 * @return void
 */
public void run(Object p_Object, String p_Method, Object[] p_Params) {
    m_Call = new SFACallable<Object>(m_ctx, p_Object, p_Method, p_Params);
    m_FutureTask = new SFAFutureTask<Object>(m_Call);
    ExecutorService executor = Executors.newFixedThreadPool(1);

    executor.execute(m_FutureTask);
}

From source file:com.netflix.nicobar.cassandra.CassandraArchiveRepositoryTest.java

@Test
@SuppressWarnings("unchecked")
public void testGetRows() throws Exception {
    EnumSet<Columns> columns = EnumSet.of(Columns.module_id, Columns.module_name);
    Rows<String, String> mockRows = mock(Rows.class);
    Row<String, String> row1 = mock(Row.class);
    Row<String, String> row2 = mock(Row.class);
    List<Row<String, String>> rowList = Arrays.asList(row1, row2);

    when(mockRows.iterator()).thenReturn(rowList.iterator());

    FutureTask<Rows<String, String>> future = new FutureTask<Rows<String, String>>(new Runnable() {
        @Override/* w  w  w . ja  v a 2  s.  c  o  m*/
        public void run() {
        }
    }, mockRows);
    ExecutorService executor = Executors.newFixedThreadPool(1);
    executor.execute(future);
    when(gateway.selectAsync(anyString())).thenReturn(future);

    repository.getRows(columns);
    List<String> selectList = new ArrayList<String>();
    for (int shardNum = 0; shardNum < config.getShardCount(); shardNum++) {
        selectList.add(repository.generateSelectByShardCql(columns, shardNum));
    }

    InOrder inOrder = inOrder(gateway);
    for (int shardNum = 0; shardNum < config.getShardCount(); shardNum++) {
        inOrder.verify(gateway).selectAsync(selectList.get(shardNum));
    }
}

From source file:com.cm2000.mobilecarer.MobileCarerActivity.java

private void startProtectme() {
    handler = new Handler() {
        @Override/*from  w w  w .j av  a2 s .  com*/
        public void handleMessage(Message msg) {
            dialog.dismiss();
            Context context = getApplicationContext();
            CharSequence text = "Protect me started";//CurrentMessage;
            int duration = Toast.LENGTH_LONG;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }
    };
    dialog = ProgressDialog.show(this, "Mobile Carer", getResources().getString(R.string.startprotectme));
    ExecutorService executor = Executors.newFixedThreadPool(1);
    executor.execute(new MenuBuilder());
}

From source file:com.cm2000.mobilecarer.MobileCarerActivity.java

private void stopStartShift() {
    // TODO Auto-generated method stub
    handler = new Handler() {
        @Override//w w w  .ja  v  a2  s  . com
        public void handleMessage(Message msg) {
            dialog.dismiss();
            Context context = getApplicationContext();
            CharSequence text = "Start/stop shift started";//CurrentMessage;
            int duration = Toast.LENGTH_LONG;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }
    };

    dialog = ProgressDialog.show(this, "Mobile Carer", getResources().getString(R.string.startstopshift));
    ExecutorService executor = Executors.newFixedThreadPool(1);
    executor.execute(new MenuBuilder());
}

From source file:org.eclipse.recommenders.stacktraces.rcp.actions.LogErrorsAction.java

private void logStressTest() {
    ExecutorService pool = Executors.newFixedThreadPool(200);
    final Random random = new Random();
    for (int i = 0; i < 100000; i++) {
        pool.execute(new Runnable() {

            @Override//w  ww . j a v  a  2 s  .  c  om
            public void run() {
                RuntimeException ex = new IllegalArgumentException("cause");
                StackTraceElement[] trace = createRandomTrace();
                ex.setStackTrace(trace);
                final Status status = new Status(IStatus.ERROR, "org.eclipse.recommenders.stacktraces.rcp",
                        "error", ex);
                if (random.nextBoolean()) {
                    log.log(status);
                } else {
                    if (random.nextBoolean()) {
                        Display.getDefault().syncExec(new ExecuteLog(status));
                    } else {
                        Display.getDefault().asyncExec(new ExecuteLog(status));
                    }
                }
            }
        });
    }
}

From source file:pt.webdetails.cdc.ws.HazelcastMonitorService.java

@GET
@Path("/restartMember")
@Produces("application/json")
public String restartMember(@Context HttpServletResponse response,
        @QueryParam("ip") @DefaultValue("") String ip, @QueryParam("port") Integer port) throws IOException {

    SecurityAssertions.assertIsAdmin();//w  ww.  j a va  2s .c  o m

    Member targetMember = getClusterMember(ip, port);

    if (targetMember == null) {
        Result.getError("Member " + ip + ":" + port + " not found in cluster.");
    }

    DistributedTask<Boolean> distributedShutdown = new DistributedTask<Boolean>(new DistributedRestart(),
            targetMember);

    ExecutorService execService = HazelcastManager.INSTANCE.getHazelcast().getExecutorService();
    execService.execute(distributedShutdown);

    try {
        Boolean result = distributedShutdown.get();
        return Result.getOK(result).toString();
    } catch (Exception e) {
        return Result.getFromException(e).toString();
    }
}

From source file:pt.webdetails.cdc.ws.HazelcastMonitorService.java

@GET
@Path("/shutdownMember")
@Produces("application/json")
public String shutdownMember(@Context HttpServletResponse response,
        @QueryParam("ip") @DefaultValue("") String ip, @QueryParam("port") Integer port) throws IOException {

    SecurityAssertions.assertIsAdmin();//www  . jav a 2  s.  co m

    Member targetMember = getClusterMember(ip, port);

    if (targetMember == null) {
        Result.getError("Member " + ip + ":" + port + " not found in cluster.");
    }

    DistributedTask<Boolean> distributedShutdown = new DistributedTask<Boolean>(new DistributedShutdown(),
            targetMember);

    ExecutorService execService = HazelcastManager.INSTANCE.getHazelcast().getExecutorService();
    execService.execute(distributedShutdown);

    try {
        Boolean result = distributedShutdown.get();
        return Result.getOK(result).toString();
    } catch (MemberLeftException e) {
        //member will leave before being able to respond
        return Result.getOK(e.getMessage()).toString();
    } catch (Exception e) {
        return Result.getFromException(e).toString();
    }

}