当前位置: 首页>>代码示例>>Java>>正文


Java Executors.newSingleThreadExecutor方法代码示例

本文整理汇总了Java中java.util.concurrent.Executors.newSingleThreadExecutor方法的典型用法代码示例。如果您正苦于以下问题:Java Executors.newSingleThreadExecutor方法的具体用法?Java Executors.newSingleThreadExecutor怎么用?Java Executors.newSingleThreadExecutor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.Executors的用法示例。


在下文中一共展示了Executors.newSingleThreadExecutor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public static void main(String args[]) {

        ExecutorService cachedThreadPool = Executors.newSingleThreadExecutor();

        for (int i = 0; i < 10; i++) {
            final int index = i;
            cachedThreadPool.execute(() -> {
                System.out.println("--->" + index);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }

        System.out.println("-----------");

    }
 
开发者ID:MinsxCloud,项目名称:minsx-java-example,代码行数:20,代码来源:SingleThreadPool.java

示例2: offer

import java.util.concurrent.Executors; //导入方法依赖的package包/类
/**
 * 向缓存文件中写入数据
 * @param data 待写入数据
 * @throws IOException
 */
public void offer(T data) throws IOException {
	logAccessFile.writeCacheAsJson(data);
	if (timeout){
		synchronized (lock) {
			if (pool == null || pool.isShutdown()) {
				pool = Executors.newSingleThreadExecutor();
			}
			if (future == null || future.isDone()){
				future = pool.submit(this);
			}
		}
	}else {
		if (pool == null || pool.isShutdown()) {
			pool = Executors.newSingleThreadExecutor();
		}
		if (future == null || future.isDone()){
			future = pool.submit(this);
		}
	}
}
 
开发者ID:andy-huaan,项目名称:data-queue,代码行数:26,代码来源:DataQueueExecutor.java

示例3: initView

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private void initView(){

        face1Result = (ImageView) findViewById(R.id.face1);
        btnToggleCamera = (ImageButton) findViewById(R.id.btnToggleCamera);
        btnGetFace = (ImageButton) findViewById(R.id.btnGetFace);
        btnGetInto = (Button) findViewById(R.id.btnGetInto);
        btnSignup =(Button) findViewById(R.id.btnsignup);
        surfaceView =  (SurfaceView) findViewById(R.id.surfaceView);
        surfaceHolder = surfaceView.getHolder();
        mGlobal = (Global) getApplicationContext();
        mInterface = new CameraInterface(MainActivity.this);
        executor = Executors.newSingleThreadExecutor();
        loader = Global.loader;
        faceView = (FaceView) findViewById(R.id.face_view);
        faceView = (FaceView) findViewById(R.id.face_view);

    }
 
开发者ID:MarukoZ,项目名称:FaceRecognition,代码行数:18,代码来源:MainActivity.java

示例4: setBasicProperties

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private void setBasicProperties () {
    final NioParams nioParams = new NioParams()
            .setNbIoThreads(1)
            .setWriteEnqueuingTimeoutInMs(0)
            .setWriteByteBufferSize(VALUE_SET_WRITE_BUFFER_SIZE);

    RABBITMQ_CONNECTION_FACTORY.useNio();
    RABBITMQ_CONNECTION_FACTORY.setNioParams(nioParams);
    RABBITMQ_CONNECTION_FACTORY.setConnectionTimeout(VALUE_CONNECTION_TIMEOUT_MS);
    RABBITMQ_CONNECTION_FACTORY.setChannelRpcTimeout(VALUE_RPC_CALL_TIMEOUT_MS);
    RABBITMQ_CONNECTION_FACTORY.setHandshakeTimeout(VALUE_HANDSHAKE_CONNECTION_TIMEOUT_MS);

    ExecutorService shutdownExecutor = Executors.newSingleThreadExecutor();
    RABBITMQ_CONNECTION_FACTORY.setShutdownExecutor(shutdownExecutor);

    RABBITMQ_CONNECTION_FACTORY.setShutdownTimeout(VALUE_SHUTDOWN_TIMEOUT_MS);
    RABBITMQ_CONNECTION_FACTORY.setRequestedHeartbeat(VALUE_REQUESTED_HEART_BEAT);
    RABBITMQ_CONNECTION_FACTORY.setAutomaticRecoveryEnabled(VALUE_AUTOMATIC_RECOVERY);
    RABBITMQ_CONNECTION_FACTORY.setTopologyRecoveryEnabled(VALUE_AUTOMATIC_EXCHANGE_RECOVERY);
    RABBITMQ_CONNECTION_FACTORY.setNetworkRecoveryInterval(VALUE_AUTOMATIC_RECOVERY_NETWORK_DELAY_MS);
    RABBITMQ_CONNECTION_FACTORY.setVirtualHost(this.virtualHost);
    RABBITMQ_CONNECTION_FACTORY.setSocketConfigurator(new DefaultSocketConfigurator() {
        @Override
        public void configure(Socket socket) throws IOException {
            socket.setTcpNoDelay(VALUE_DONT_USE_NAGLE);
            socket.setReceiveBufferSize(VALUE_SET_WRITE_BUFFER_SIZE);
            socket.setSendBufferSize(VALUE_SET_SEND_BUFFER_SIZE);
            socket.setPerformancePreferences(0, 2, 1);
            socket.setReuseAddress(true);
            socket.setKeepAlive(VALUE_TCP_KEELALIVE);
            socket.setSoLinger(true, 1000);
        }
    });
}
 
开发者ID:LeeKyoungIl,项目名称:illuminati,代码行数:35,代码来源:RabbitmqInfraTemplateImpl.java

示例5: testRead

import java.util.concurrent.Executors; //导入方法依赖的package包/类
/**
 * Test of read method, of class UART.
 *
 * @throws java.lang.InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 */
@Test
public void testRead() throws InterruptedException, ExecutionException, TimeoutException {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Semaphore semaphore = new Semaphore(0);
    mockInput = '5';
    Future<Void> future = executor.submit(() -> {
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        ScheduledFuture<?> releaserHandle = scheduler.schedule(() -> {
            semaphore.release();
        }, 5, TimeUnit.SECONDS);
        uart.read();
        releaserHandle.get(5, TimeUnit.SECONDS);
        return null;
    });
    semaphore.tryAcquire(15, TimeUnit.SECONDS);
    uart.feed(mockInput);
    future.get(25, TimeUnit.SECONDS);
    assertEquals("UART read result is wrong.", mockInput, registerFile.getValue("r0"));
}
 
开发者ID:kasirgalabs,项目名称:ETUmulator,代码行数:27,代码来源:UARTTest.java

示例6: EditorPaneController

import java.util.concurrent.Executors; //导入方法依赖的package包/类
/**
 * <p>Creates the controller for the {@link EditorPane}.</p>
 *
 * @param code         the code file to be shown
 * @param globalConfig the global configuration (for font size or style)
 */
public EditorPaneController(Code code, GlobalConfig globalConfig) {
    this.code = code;
    this.view = new EditorPane(code.getSourcecode(),
            code.syntaxErrorsProperty());
    this.globalConfig = globalConfig;
    this.globalConfig.showLineNumbersProperty()
            .addListener(new ShowLineNumbersListener());
    this.view.getStylesheets()
            .add(EditorPane.class.getResource("st-keywords.css")
                    .toExternalForm());
    this.executor = Executors.newSingleThreadExecutor();
    configureTextArea();
    setupContextMenu();
    handleTextChange(computeHighlighting(code.getSourcecode()));
    this.globalConfig.editorFontSizeProperty().addListener(
            (observable, oldValue, newValue) -> updateFontSize(
                    newValue.intValue()));
    this.globalConfig.editorFontFamilyProperty().addListener(
            (observable, oldValue, newValue) -> updateFontFamily(newValue));
    updateFontFamily(globalConfig.getEditorFontFamily());
    updateFontSize(globalConfig.getEditorFontSize());
    filterAltEvents();
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:30,代码来源:EditorPaneController.java

示例7: onKeyEvent

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Override
protected boolean onKeyEvent(final KeyEvent event) {
    if (mKeyEventExecutor == null) {
        mKeyEventExecutor = Executors.newSingleThreadExecutor();
    }
    mKeyEventExecutor.execute(new Runnable() {
        @Override
        public void run() {
            stickOnKeyObserver.onKeyEvent(event.getKeyCode(), event);
            mOnKeyObserver.onKeyEvent(event.getKeyCode(), event);
        }
    });
    return false;
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:15,代码来源:AccessibilityService.java

示例8: itExecutesReturnedExceptionalFuturesOnTheProvidedExecutor

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Test
public void itExecutesReturnedExceptionalFuturesOnTheProvidedExecutor() {
  ExecutorService executorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("SmtpSessionTestExecutor").build());
  SmtpSession session = new SmtpSession(channel, responseHandler, CONFIG, executorService, SSL_ENGINE_SUPPLIER);

  CompletableFuture<SmtpClientResponse> future = session.send(SMTP_REQUEST);
  CompletableFuture<Boolean> assertionFuture = future.handle((r, e) -> {
    assertThat(Thread.currentThread().getName()).contains("SmtpSessionTestExecutor");
    return true;
  });

  responseFuture.completeExceptionally(new RuntimeException());
  assertionFuture.join();
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:15,代码来源:SmtpSessionTest.java

示例9: generate

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@SuppressWarnings("resource")
@Override
public InputStream generate(Integration integration) throws IOException {
    final PipedInputStream is = new PipedInputStream();
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final PipedOutputStream os = new PipedOutputStream(is);

    executor.execute(generateAddProjectTarEntries(integration, os));

    return is;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:12,代码来源:DefaultProjectGenerator.java

示例10: start

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Override
public void start ( final BundleContext bundleContext ) throws Exception
{
    Activator.context = bundleContext;
    this.executor = Executors.newSingleThreadExecutor ( new NamedThreadFactory ( "HistoricalProxyItem" ) );
    this.service = new ProxyItemFactory ( bundleContext, this.executor );

    final Dictionary<String, Object> properties = new Hashtable<String, Object> ();
    properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
    properties.put ( Constants.SERVICE_DESCRIPTION, "A historical item that proxies access to a set of other items at the same time, merging the result based on the quality." );
    properties.put ( ConfigurationAdministrator.FACTORY_ID, "org.eclipse.scada.hd.server.proxy" );
    bundleContext.registerService ( ConfigurationFactory.class.getName (), this.service, properties );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:14,代码来源:Activator.java

示例11: startWithURL

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private void startWithURL(String url, String postData) {
    Log.i(TAG, "Cronet started: %s", url);
    mUrl = url;

    Executor executor = Executors.newSingleThreadExecutor();
    UrlRequest.Callback callback = new SimpleUrlRequestCallback();
    UrlRequest.Builder builder = new UrlRequest.Builder(url, callback, executor, mCronetEngine);
    applyPostDataToUrlRequestBuilder(builder, executor, postData);
    builder.build().start();
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:11,代码来源:CronetSampleActivity.java

示例12: getExecutor

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public static ExecutorService getExecutor() {
    if (executor == null) {
        executor = Executors.newSingleThreadExecutor();
    }
    return executor;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:EditorTestBase.java

示例13: getExecutor

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private synchronized ExecutorService getExecutor() {
    if (executor == null) executor = Executors.newSingleThreadExecutor();
    return executor;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:LiveCPUView.java

示例14: WXWorkThreadManager

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public WXWorkThreadManager() {
  singleThreadExecutor = Executors.newSingleThreadExecutor();
}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:4,代码来源:WXWorkThreadManager.java

示例15: PeerConnectionClient

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private PeerConnectionClient() {
    // Executor thread is started once in private ctor and is used for all
    // peer connection API calls to ensure new peer connection factory is
    // created on the same thread as previously destroyed factory.
    executor = Executors.newSingleThreadExecutor();
}
 
开发者ID:nhancv,项目名称:nc-android-webrtcpeer,代码行数:7,代码来源:PeerConnectionClient.java


注:本文中的java.util.concurrent.Executors.newSingleThreadExecutor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。