Example usage for java.util.concurrent Executors newSingleThreadExecutor

List of usage examples for java.util.concurrent Executors newSingleThreadExecutor

Introduction

In this page you can find the example usage for java.util.concurrent Executors newSingleThreadExecutor.

Prototype

public static ExecutorService newSingleThreadExecutor() 

Source Link

Document

Creates an Executor that uses a single worker thread operating off an unbounded queue.

Usage

From source file:com.gnizr.core.robot.rss.CrawlRssFeed.java

public CrawlRssFeed() {
    saveBookmarkEntriesExecutor = Executors.newSingleThreadExecutor();
    serviceEnabled = false;
    ageHour = 2;
}

From source file:io.undertow.servlet.test.request.ExecutorPerServletTestCase.java

@Before
public void setup() throws ServletException {
    DeploymentUtils.setupServlet(new ServletInfo("racey", RaceyAddServlet.class).addMapping("/racey"),
            new ServletInfo("single", RaceyAddServlet.class).addMapping("/single")
                    .setExecutor(executorService = Executors.newSingleThreadExecutor()));
}

From source file:hivemall.mix.server.MixServerTest.java

@Test
public void testSimpleScenario() throws InterruptedException {
    int port = NetUtils.getAvailablePort();
    CommandLine cl = CommandLineUtils.parseOptions(
            new String[] { "-port", Integer.toString(port), "-sync_threshold", "3" }, MixServer.getOptions());
    MixServer server = new MixServer(cl);
    ExecutorService serverExec = Executors.newSingleThreadExecutor();
    serverExec.submit(server);//ww  w.j  av a 2  s  .  c  om

    waitForState(server, ServerState.RUNNING);

    PredictionModel model = new DenseModel(16777216, false);
    model.configureClock();
    MixClient client = null;
    try {
        client = new MixClient(MixEventName.average, "testSimpleScenario", "localhost:" + port, false, 2,
                model);
        model.configureMix(client, false);

        final Random rand = new Random(43);
        for (int i = 0; i < 100000; i++) {
            Integer feature = Integer.valueOf(rand.nextInt(100));
            float weight = (float) rand.nextGaussian();
            model.set(feature, new WeightValue(weight));
        }

        Thread.sleep(5000L);

        long numMixed = model.getNumMixed();
        Assert.assertEquals("number of mix events: " + numMixed, numMixed, 0L);

        serverExec.shutdown();
    } finally {
        IOUtils.closeQuietly(client);
    }
}

From source file:de.dfki.iui.mmds.scxml.engine.SCXMLEngineActivator.java

/**
 * /*from   w ww. ja v a  2  s .c  o m*/
 * 
 * @param id
 * @param state
 */
public static void sendScxmlOnEntryEvent(final String id, final TransitionTarget state) {
    if (getEventAdmin() == null)
        return;
    Executors.newSingleThreadExecutor().execute(new Runnable() {
        @Override
        public void run() {
            getEventAdmin().sendEvent(new SCXMLOnEntryEvent(id, state));
        }
    });
}

From source file:maltcms.ui.fileHandles.serialized.JFCOpenSupport.java

@Override
protected CloneableTopComponent createCloneableTopComponent() {
    final JFCDataObject dobj = (JFCDataObject) entry.getDataObject();
    final JFCTopComponent tc = new JFCTopComponent();
    tc.setDisplayName(dobj.getName());//from w ww . j a  v  a 2  s  .c  om

    final ProgressHandle ph = ProgressHandleFactory
            .createHandle("Loading file " + dobj.getPrimaryFile().getName());
    tc.setDisplayName(dobj.getPrimaryFile().getName());
    final ExecutorService es = Executors.newSingleThreadExecutor();

    final Future<JFreeChart> f = es.submit(new JFCLoader(dobj.getPrimaryFile().getPath(), ph));
    try {
        tc.setChart(f.get());
    } catch (InterruptedException | ExecutionException ex) {
        Exceptions.printStackTrace(ex);
    } finally {
        ph.finish();
    }

    return tc;
}

From source file:ch.jamiete.hilda.plugins.PluginManager.java

public void disablePlugins() {
    ExecutorService executor = Executors.newSingleThreadExecutor();

    synchronized (this.plugins) {
        final Iterator<HildaPlugin> iterator = this.plugins.iterator();

        while (iterator.hasNext()) {
            final HildaPlugin entry = iterator.next();

            Future<?> future = executor.submit(() -> {
                try {
                    entry.onDisable();/*from   w ww  .ja v a 2s. co m*/
                } catch (final Exception e) {
                    Hilda.getLogger().log(Level.WARNING, "Encountered an exception while disabling plugin "
                            + entry.getPluginData().getName(), e);
                }
            });

            try {
                future.get(30, TimeUnit.SECONDS);
            } catch (InterruptedException | ExecutionException | TimeoutException e) {
                Hilda.getLogger().log(Level.WARNING, "Plugin " + entry.getPluginData().getName()
                        + " took too long disabling; ceased executing its code", e);
            }
        }
    }

    executor.shutdown();

    try {
        executor.awaitTermination(5, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Hilda.getLogger().log(Level.WARNING, "Encountered an exception during the plugin disable grace period",
                e);
    }
}

From source file:io.joynr.messaging.bounceproxy.monitoring.BounceProxyStartupReporterTest.java

@Before
public void setUp() {

    Properties properties = new Properties();
    properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_SEND_LIFECYCLE_REPORT_RETRY_INTERVAL_MS, "50");
    properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_CONTROLLER_BASE_URL, "http://anyurl.com");
    properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_ID, "X.Y");
    properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_BPC, "http://anyurl.com");
    properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_CC, "http://anyurl.com");

    Injector injector = Guice.createInjector(new PropertyLoadingModule(properties), new AbstractModule() {

        @Override/*  w w w.j  a v  a 2 s  .  c om*/
        protected void configure() {
            bind(ExecutorService.class).toInstance(Executors.newSingleThreadExecutor());
            bind(CloseableHttpClient.class).toInstance(HttpClients.createMinimal());
        }

    });

    startupReporter = injector.getInstance(BounceProxyStartupReporter.class);
    execService = injector.getInstance(ExecutorService.class);
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.batch.actor.supervisor.CategorisationSupervisorRunner.java

@Override
public void run(String... args) throws Exception {
    Executors.newSingleThreadExecutor().submit(() -> {
        trackDeadLetters();//  w ww. j  a v  a 2s.co m
        actorSystem.actorOf(Props.create(CategorisationSupervisorActor.class, nbOfDocsToCategoriseAtATime,
                iaViewService, categoriserService), "supervisorActor");
    });
}

From source file:bemap.SimpleSerial.java

public int searchDevicePort() throws InterruptedException {
    String[] portNames = SerialPortList.getPortNames();
    if (SERIAL_DEBUG)
        BeMapEditor.mainWindow.append("\nFound ports: " + Arrays.toString(portNames));
    int portNumber = -1;
    for (int i = 0; i < portNames.length; i++) {

        currentPortName = portNames[i];/*  w ww .j a v a 2 s . c o  m*/

        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<String> future = executor.submit(new PortSearchTask());

        try {
            String returnPort = future.get(3, TimeUnit.SECONDS);
            if (!"NULL".equals(returnPort)) {
                portNumber = i;
                i = portNames.length; //quit loop
            }

        } catch (ExecutionException ex) {
            Logger.getLogger(SimpleSerial.class.getName()).log(Level.SEVERE, null, ex);
        } catch (TimeoutException ex) {
            Logger.getLogger(SimpleSerial.class.getName()).log(Level.SEVERE, null, ex);
            if (SERIAL_DEBUG)
                BeMapEditor.mainWindow.append("\nOpening port " + currentPortName + " has timed out");
        }

        executor.shutdownNow();
    }
    if (portNumber < 0) {
        deviceConnected = false;
        return 0;
    } else {
        serialPortName = portNames[portNumber];
        deviceConnected = true;
        if (SERIAL_DEBUG)
            BeMapEditor.mainWindow.append("\nDevice detected on port " + serialPortName);
        return 1; //success
    }
}

From source file:com.github.ljtfreitas.restify.http.spring.client.call.exec.DeferredResultEndpointCallExecutableFactory.java

public DeferredResultEndpointCallExecutableFactory() {
    this(Executors.newSingleThreadExecutor());
}