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:co.kuali.coeus.sys.impl.persistence.SchemaSpyFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    Executors.newSingleThreadExecutor().execute(refreshSchemaSpy);
}

From source file:org.jhk.pulsing.web.service.prod.PulseService.java

@Override
public void init() {
    super.init();

    final List<Pulse> entries = new LinkedList<>();
    for (int createCount = 0; createCount < 10; createCount++) {
        Pulse pulse = org.jhk.pulsing.web.dao.dev.PulseDao.createMockedPulse();
        pulse.setAction(ACTION.SUBSCRIBE);
        entries.add(pulse);//from w  w w  . ja  v  a 2 s  . c o  m
    }

    tempEService = Executors.newSingleThreadExecutor();
    tempEService.submit(() -> {

        long userId = 1000L;
        for (int loop = 0; loop < 20; loop++) {
            try {
                TimeUnit.SECONDS.sleep(10);

                Pulse pulse = entries.get((int) Math.random() * entries.size());
                pulse.getUserId().setId(userId++);
                subscribePulse(pulse);

                _LOGGER.debug("Submitted..." + pulse.getValue());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });
}

From source file:io.lqd.sdk.Liquid.java

private Liquid(Context context, String apiToken, boolean developmentMode) {
    LiquidTools.checkForPermission(permission.INTERNET, context);
    if (apiToken == null || apiToken.length() == 0) {
        throw new IllegalArgumentException("Your API Token is invalid: \'" + apiToken + "\'.");
    }/*  w  ww. j a  v  a2 s .c om*/
    mContext = context;
    if (Build.VERSION.SDK_INT >= 14) {
        attachActivityCallbacks();
    }
    mSessionTimeout = LIQUID_DEFAULT_SESSION_TIMEOUT;
    mApiToken = apiToken;
    mDevice = new LQDevice(context, LIQUID_VERSION);
    mQueue = Executors.newSingleThreadExecutor();
    mLoadedLiquidPackage = LQLiquidPackage.loadFromDisk(mContext);
    mHttpQueuer = new LQQueuer(mContext, mApiToken, LQNetworkRequest.loadQueue(mContext, mApiToken));
    mHttpQueuer.startFlushTimer();
    isDevelopmentMode = developmentMode;
    if (isDevelopmentMode)
        mBundleVariablesSended = new ArrayList<String>();

    // Get last user and init session
    mPreviousUser = LQUser.load(mContext, mApiToken);
    identifyUser(mPreviousUser.getIdentifier(), mPreviousUser.getAttributes(), null,
            mPreviousUser.isIdentified(), false);

    LQLog.info("Initialized Liquid with API Token " + apiToken);
}

From source file:com.netflix.curator.framework.recipes.barriers.TestDistributedBarrier.java

@Test
public void testBasic() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try {//from  ww w  . j  a v  a2  s  .co m
        client.start();

        final DistributedBarrier barrier = new DistributedBarrier(client, "/barrier");
        barrier.setBarrier();

        ExecutorService service = Executors.newSingleThreadExecutor();
        service.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                Thread.sleep(1000);
                barrier.removeBarrier();
                return null;
            }
        });

        Assert.assertTrue(barrier.waitOnBarrier(10, TimeUnit.SECONDS));
    } finally {
        client.close();
    }
}

From source file:com.syncedsynapse.kore2.jsonrpc.HostConnection.java

/**
 * Creates a new host connection// w ww .ja  v  a2  s .  c o m
 * @param hostInfo Host info object
 * @param connectTimeout Connection timeout in ms
 */
public HostConnection(final HostInfo hostInfo, int connectTimeout) {
    this.hostInfo = hostInfo;
    // Start with the default host protocol
    this.protocol = hostInfo.getProtocol();
    // Create a single threaded executor
    this.executorService = Executors.newSingleThreadExecutor();
    // Set timeout
    this.connectTimeout = connectTimeout;
}

From source file:fr.bmartel.speedtest.SpeedTestTask.java

/**
 * initialize thread pool./*  www  . j  a v a2 s. c om*/
 */
private void initThreadPool() {
    mReadExecutorService = Executors.newSingleThreadExecutor();
    mReportExecutorService = Executors.newScheduledThreadPool(SpeedTestConst.THREAD_POOL_REPORT_SIZE);
    mWriteExecutorService = Executors.newSingleThreadExecutor();
}

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

/**
 * Informs all interested listeners/handlers about the new state of the
 * engine 'id' and provides a list of available events and the corresponding
 * states (needed for Debug View) where the events can be taken.
 * // ww w  . j a v a2  s . c o m
 * @param id
 *            - The id of the engine that changed its state.
 * @param state
 *            - The state which the engine changed to.
 * @param availableEventsStates
 *            - The map containing all available events and the
 *            corresponding states.
 */
public static void sendScxmlState(final String id, final State state,
        final Map<String, Map<String, List<Object[]>>> availableEventsStates) {
    if (getEventAdmin() == null)
        return;
    Executors.newSingleThreadExecutor().execute(new Runnable() {
        @Override
        public void run() {
            getEventAdmin().postEvent(new SCXMLEngineStateChangedEvent(id, state, availableEventsStates));
        }
    });
}

From source file:com.metamx.druid.merger.coordinator.TaskLifecycleTest.java

@Before
public void setUp() {
    EmittingLogger.registerEmitter(EasyMock.createMock(ServiceEmitter.class));

    tmp = Files.createTempDir();//from w w w .java  2  s .c  o m

    ts = new HeapMemoryTaskStorage();
    tl = new TaskLockbox(ts);
    tq = new TaskQueue(ts, tl);
    mdc = newMockMDC();

    tb = new TaskToolboxFactory(new TaskConfig() {
        @Override
        public File getBaseTaskDir() {
            return tmp;
        }

        @Override
        public int getDefaultRowFlushBoundary() {
            return 50000;
        }

        @Override
        public String getHadoopWorkingPath() {
            return null;
        }
    }, new LocalTaskActionClientFactory(ts, new TaskActionToolbox(tq, tl, mdc, newMockEmitter())),
            newMockEmitter(), null, // s3 client
            new DataSegmentPusher() {
                @Override
                public DataSegment push(File file, DataSegment segment) throws IOException {
                    return segment;
                }
            }, new DataSegmentKiller() {
                @Override
                public void kill(DataSegment segments) throws SegmentLoadingException {

                }
            }, null, // segment announcer
            null, // new segment server view
            null, // query runner factory conglomerate corporation unionized collective
            new DefaultObjectMapper());

    tr = new LocalTaskRunner(tb, Executors.newSingleThreadExecutor());

    tc = new TaskConsumer(tq, tr, tb, newMockEmitter());
    tsqa = new TaskStorageQueryAdapter(ts);

    tq.start();
    tc.start();
}

From source file:com.smartitengineering.loadtest.engine.impl.LoadTestEngineImpl.java

private void initializeFinishDetector() {

    finishedDetector = new EngineJobFinishedDetector();
    executorService = Executors.newSingleThreadExecutor();
}

From source file:it.unibo.alchemist.modelchecker.AlchemistASMC.java

/**
 * @param xmlFilePath// w w  w  .j a v  a 2 s . c  om
 *            Alchemist XML specification to execute
 * @param steps
 *            maximum length of the simulation in steps
 * @param finalTime
 *            maximum length of the simulation in simulated time units
 */
public void execute(final String xmlFilePath, final long steps, final double finalTime) {
    final ExecutorService ex = Executors.newSingleThreadExecutor();
    ex.execute(new Runnable() {
        public void run() {
            try {
                nr = minN;
                final byte[] ba = mx.serializedEnvironment(xmlFilePath);
                EnvironmentBuilder<T> ebo;
                ebo = new EnvironmentBuilder<>(xmlFilePath);
                ebo.buildEnvironment();
                final RandomEngine random = new MersenneTwister();
                random.setSeed(ebo.getRandomEngine().getSeed());

                mx.addJob(ba, random, minN, steps, finalTime);
                mx.waitForCompletion();
                notifyASMCListeners();
                while (!stopCondition()) {
                    nr += SAMPLESTEP;
                    // pList.ensureCapacity(INCREASE);
                    mx.addJob(ba, random, SAMPLESTEP, steps, finalTime);
                    mx.waitForCompletion();
                    notifyASMCListeners();
                }
                mx.destroy();
                exec.release();
            } catch (InstantiationException | IllegalAccessException | InvocationTargetException
                    | ClassNotFoundException | SAXException | IOException | ParserConfigurationException e) {
                L.error(e);
            }
        }

    });

}