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


Java Executors.newFixedThreadPool方法代码示例

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


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

示例1: main

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public static void main(String[] args) {
	ExecutorService pool = Executors.newFixedThreadPool(50);
	for(int i=0;i<50;i++){
		pool.execute(new Runnable() {
			@Override
			public void run() {
				while(true){
					Map<String, String> data = new HashMap<String, String>();
					data.put("q", "SELECT MAX(value) FROM sensor where device_code='d_bt_0' and sensor_code='s_btg_8' and time>=1485541192230000000 and time<=1485627592230000000");
					HttpRequest.post("http://10.77.110.226:8086/query?db=ruc_test1").form(data).code();
				}
			}
		});
	}
	try {
		pool.awaitTermination(Long.MAX_VALUE,TimeUnit.DAYS);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:21,代码来源:HttpRequestTest.java

示例2: testMultipleClients

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Test
public void testMultipleClients() throws Exception {
  ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS);
  try {
    ExecutorCompletionService<Boolean> ecs =
        new ExecutorCompletionService<Boolean>(exec);
    for (int i = 0; i < NUM_THREADS; ++i)
      ecs.submit(new IdLockTestThread("client_" + i));
    for (int i = 0; i < NUM_THREADS; ++i) {
      Future<Boolean> result = ecs.take();
      assertTrue(result.get());
    }
    idLock.assertMapEmpty();
  } finally {
    exec.shutdown();
    exec.awaitTermination(5000, TimeUnit.MILLISECONDS);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:TestIdLock.java

示例3: main

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public static void main(String args[]) {
    ExecutorService executor = Executors.newFixedThreadPool(10);
    Callable<TimeZone> calTimeZone = () -> TimeZone.getDefault();
    List<Callable<TimeZone>> tasks = new ArrayList<>();
    for (int j = 1; j < 10; j++) {
        tasks.add(calTimeZone);
    }
    try {
        List<Future<TimeZone>> results = executor.invokeAll(tasks);
        for (Future<TimeZone> f : results) {
            TimeZone tz = f.get();
            if (! tz.getID().equals("GMT")) {
                throw new RuntimeException("wrong Time zone ID: " + tz.getID()
                        + ", It should be GMT");
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException("Execution interrupted or Execution Exception occurred", e);
    } finally {
        executor.shutdown();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:Bug8066652.java

示例4: match

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public static MatchResult match(Mat scene, Mat[] templs, Method method, double scaleFactor){
		
	MatchRunner[] t = new MatchRunner[templs.length];
	ExecutorService sr = Executors.newFixedThreadPool(templs.length);
	for(int i = 0; i < templs.length; i++){
		t[i] = new MatchRunner(scene,templs[i],method,scaleFactor);
		sr.execute(t[i]);
	}
	try {
		sr.shutdown();
		sr.awaitTermination(1, TimeUnit.DAYS);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	
	MatchResult best = findBestMatch(t);
	/*if(best != null){
		Imgproc.circle(scene, new Point(best.centerx +best.scaleFactor,best.centery +best.scaleFactor) ,3,new Scalar(51,51,51));
		//Imgproc.circle(scene, new Point(best.center.x ,best.center.y ) ,3,new Scalar(50,203,122));
		Imgcodecs.imwrite("/home/klein/dev/frc/test.png", scene);
	}*/
	return best;
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:24,代码来源:CvTemplateMatcher.java

示例5: Peer

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public Peer(String host, int port) throws ConnectException {
    mConnection = Connection.fromAddress(host, port);
    if (mConnection == null) {
        throw new ConnectException("Failed to create connection");
    }

    mConnectionListener = new Connection.ConnectionListener() {
        @Override
        public void onReceived(@NonNull byte[] received) {
            handleReceiveBytes(received);
        }
    };

    mReceiveMessageService = Executors.newFixedThreadPool(1);
    mReceivedMessageBuffer = new ArrayList<>();
}
 
开发者ID:forusoul70,项目名称:playTorrent,代码行数:17,代码来源:Peer.java

示例6: testOfferInExecutor

import java.util.concurrent.Executors; //导入方法依赖的package包/类
/**
 * offer transfers elements across Executor tasks
 */
public void testOfferInExecutor() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
    q.add(one);
    q.add(two);
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try (PoolCleaner cleaner = cleaner(executor)) {
        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(q.offer(three));
                threadsStarted.await();
                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
                assertEquals(0, q.remainingCapacity());
            }});

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertSame(one, q.take());
            }});
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:LinkedBlockingDequeTest.java

示例7: main

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

        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);

        fixedThreadPool.execute(() -> {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

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


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

示例8: activate

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Activate
public void activate(ComponentContext context) {
    alarmsExecutor = Executors.newScheduledThreadPool(CORE_POOL_SIZE);
    eventHandlingExecutor =
            Executors.newFixedThreadPool(CORE_POOL_SIZE,
                                         groupedThreads("onos/pollingalarmprovider",
                                                        "device-installer-%d", log));

    providerService = providerRegistry.register(this);

    deviceService.addListener(deviceListener);
    mastershipService.addListener(mastershipListener);

    if (context == null) {
        alarmPollFrequencySeconds = DEFAULT_POLL_FREQUENCY_SECONDS;
        log.info("No component configuration");
    } else {
        Dictionary<?, ?> properties = context.getProperties();
        alarmPollFrequencySeconds = getNewPollFrequency(properties, alarmPollFrequencySeconds);
    }
    scheduledTask = schedulePolling();
    log.info("Started");
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:PollingAlarmProvider.java

示例9: run

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Override
public void run(String... args) {
    Client client = new Client.Builder()
            .setBaseUrl(baseUrl)
            .setClientId(clientId)
            .setClientSecret(clientSecret)
            .setUsername(username)
            .setPassword(password)
            .build();

    BlockingQueue<String> loanQueue = new LinkedBlockingQueue();
    ExecutorService service = Executors.newFixedThreadPool(4);

    LoanChangeWatcher watcher = new LoanChangeWatcher(client, loanFolder, loanQueue, service);

    LoanProcessor processor1 = new LoanProcessor(loanQueue, client, outputFile);
    LoanProcessor processor2 = new LoanProcessor(loanQueue, client, outputFile);
    LoanProcessor processor3 = new LoanProcessor(loanQueue, client, outputFile);

    service.submit(watcher);
    service.submit(processor1);
    service.submit(processor2);
    service.submit(processor3);
}
 
开发者ID:EllieMae,项目名称:api-batchupload-sample-application,代码行数:25,代码来源:Main.java

示例10: MAF_Streamer

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public MAF_Streamer(File queryFile, File tmpFolder, Integer chunkSize, int cores, boolean doFiltering, boolean verbose) {
	this.queryFile = queryFile;
	this.tmpFolder = tmpFolder;
	this.cores = cores;
	this.verbose = verbose;
	this.doFiltering = doFiltering;
	this.executor = Executors.newFixedThreadPool(1);
	this.chunkSize = chunkSize != null ? chunkSize : this.chunkSize;
}
 
开发者ID:BenjaminAlbrecht84,项目名称:DAA_Converter,代码行数:10,代码来源:MAF_Streamer.java

示例11: parallelDrainQueue

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private void parallelDrainQueue(int threadCount) {
  ExecutorService executor = Executors.newFixedThreadPool(threadCount);
  for (int i = 0; i < threadCount; i++) {
    executor.execute(new NamedRunnable("Crawler %s", i) {
      @Override protected void execute() {
        try {
          drainQueue();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }
  executor.shutdown();
}
 
开发者ID:dave-r12,项目名称:okhttp-byte-counter,代码行数:16,代码来源:Crawler.java

示例12: runNewPool

import java.util.concurrent.Executors; //导入方法依赖的package包/类
/**
 * @param <R>
 * @param threads
 */
public static <R extends Runnable> void runNewPool(final Collection<R> threads, int max_concurrent) {
    ExecutorService pool = Executors.newFixedThreadPool(max_concurrent, factory);
    ThreadUtil.run(threads, pool, true);
}
 
开发者ID:s-store,项目名称:s-store,代码行数:9,代码来源:ThreadUtil.java

示例13: testConcurrentAccessToSystemCredentials

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Test
public void testConcurrentAccessToSystemCredentials(){
  final Map<ApplicationId, ByteBuffer> testCredentials = new HashMap<>();
  ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[300]);
  ApplicationId applicationId = ApplicationId.newInstance(123456, 120);
  testCredentials.put(applicationId, byteBuffer);

  final List<Throwable> exceptions = Collections.synchronizedList(new
      ArrayList<Throwable>());

  final int NUM_THREADS = 10;
  final CountDownLatch allDone = new CountDownLatch(NUM_THREADS);
  final ExecutorService threadPool = Executors.newFixedThreadPool(
      NUM_THREADS);

  final AtomicBoolean stop = new AtomicBoolean(false);

  try {
    for (int i = 0; i < NUM_THREADS; i++) {
      threadPool.submit(new Runnable() {
        @Override
        public void run() {
          try {
            for (int i = 0; i < 100 && !stop.get(); i++) {
              NodeHeartbeatResponse nodeHeartBeatResponse =
                  newNodeHeartbeatResponse(0, NodeAction.NORMAL,
                      null, null, null, null, 0);
              nodeHeartBeatResponse.setSystemCredentialsForApps(
                  testCredentials);
              NodeHeartbeatResponseProto proto =
                  ((NodeHeartbeatResponsePBImpl)nodeHeartBeatResponse)
                      .getProto();
              Assert.assertNotNull(proto);
            }
          } catch (Throwable t) {
            exceptions.add(t);
            stop.set(true);
          } finally {
            allDone.countDown();
          }
        }
      });
    }

    int testTimeout = 2;
    Assert.assertTrue("Timeout waiting for more than " + testTimeout + " " +
            "seconds",
        allDone.await(testTimeout, TimeUnit.SECONDS));
  } catch (InterruptedException ie) {
    exceptions.add(ie);
  } finally {
    threadPool.shutdownNow();
  }
  Assert.assertTrue("Test failed with exception(s)" + exceptions,
      exceptions.isEmpty());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:57,代码来源:TestNodeStatusUpdater.java

示例14: execute

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private void execute(Runnable runnable){
    if(mExecutorService==null){
        mExecutorService = Executors.newFixedThreadPool(3);
    }
    mExecutorService.execute(runnable);
}
 
开发者ID:natjs,项目名称:nat-network-stream,代码行数:7,代码来源:DefaultHttpAdapter.java

示例15: UploadManager

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private UploadManager() {
    executorService = Executors.newFixedThreadPool(10);
    idToTaskMap = new HashMap<>();
}
 
开发者ID:dhaval-mehta,项目名称:url-to-google-drive,代码行数:5,代码来源:UploadManager.java


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