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


Java ThreadPoolExecutor.setMaximumPoolSize方法代码示例

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


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

示例1: testingOnlyPostEvent

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void testingOnlyPostEvent ( MultiValueMap<String, String> formParams )
		throws Exception {

	// Support for LT. do not blow through queue
	if ( numSent++ % 1000 == 0 ) {
		logger.info( "Messages sent: " + numSent + " backlog: " + eventPostQueue.size() );
	}

	ThreadPoolExecutor pool = (ThreadPoolExecutor) eventPostPool;
	if ( eventPostQueue.size() > 100 && pool.getCorePoolSize() == 1 ) {
		pool.setCorePoolSize( 6 );
		pool.setMaximumPoolSize( 6 );
	}

	// blocking for testing
	logger.info( "eventPostPool terminated: {}", eventPostPool.isTerminated() );
	Future<String> futureResult = eventPostPool.submit( new EventPostRunnable( lifecycleSettings.getEventUrl(),
		formParams, "test", "test" ) );

	// Non Blocking to test event caching/pooling
	// futureResult.get() ;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:23,代码来源:CsapEventClient.java

示例2: setStartStopThreads

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void setStartStopThreads(int startStopThreads) {
    this.startStopThreads = startStopThreads;

    // Use local copies to ensure thread safety
    ThreadPoolExecutor executor = startStopExecutor;
    if (executor != null) {
        int newThreads = getStartStopThreadsInternal();
        executor.setMaximumPoolSize(newThreads);
        executor.setCorePoolSize(newThreads);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:13,代码来源:ContainerBase.java

示例3: KanboardAPI

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public KanboardAPI(String serverURL, final String username, final String password) throws IOException {
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }

        });
        kanboardURL = KanboardAPI.sanitizeURL(serverURL.trim());
        Log.i(Constants.TAG, String.format("Host uses %s", kanboardURL.getProtocol()));
//        threadPoolExecutor = new ThreadPoolExecutor(12, 12, 20, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(256));
        threadPoolExecutor = (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR;
        threadPoolExecutor.setCorePoolSize(12);
        threadPoolExecutor.setMaximumPoolSize(12);
    }
 
开发者ID:andresth,项目名称:Kandroid,代码行数:16,代码来源:KanboardAPI.java

示例4: initExecutionPool

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private void initExecutionPool(int corePoolSize, int maxPoolSize, long keepAliveTime) {
  executorPool = (ThreadPoolExecutor) Executors.newCachedThreadPool();
  executorPool.setCorePoolSize(corePoolSize);
  executorPool.setMaximumPoolSize(maxPoolSize);
  executorPool.setKeepAliveTime(keepAliveTime, TimeUnit.MILLISECONDS);

}
 
开发者ID:DSC-SPIDAL,项目名称:twister2,代码行数:8,代码来源:TaskExecutorCachedThreadPool.java

示例5: adjustPoolSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void adjustPoolSize(int newPoolSize) {
    if (newPoolSize != poolSize) {
        poolSize = newPoolSize;
        if (executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
            pool.setCorePoolSize(newPoolSize);
            pool.setMaximumPoolSize(newPoolSize);
        }
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:11,代码来源:ExecutorTemplate.java

示例6: adjustPoolSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private void adjustPoolSize(DbLoadContext context) {
    Pipeline pipeline = context.getPipeline();
    int newPoolSize = pipeline.getParameters().getLoadPoolSize();
    if (newPoolSize != poolSize) {
        poolSize = newPoolSize;
        if (executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
            pool.setCorePoolSize(newPoolSize);
            pool.setMaximumPoolSize(newPoolSize);
        }
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:13,代码来源:DbLoadAction.java

示例7: adjustPoolSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private void adjustPoolSize(FileLoadContext context) {
    Pipeline pipeline = context.getPipeline();
    int newPoolSize = pipeline.getParameters().getFileLoadPoolSize();
    if (newPoolSize != poolSize) {
        poolSize = newPoolSize;
        if (executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
            pool.setCorePoolSize(newPoolSize);
            pool.setMaximumPoolSize(newPoolSize);
        }
    }

}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:14,代码来源:FileLoadAction.java

示例8: adjustPoolSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private void adjustPoolSize(int newPoolSize) {
    if (newPoolSize != poolSize) {
        poolSize = newPoolSize;
        if (executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
            pool.setCorePoolSize(newPoolSize);
            pool.setMaximumPoolSize(newPoolSize);
        }
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:11,代码来源:DatabaseExtractor.java

示例9: setThreadPoolSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void setThreadPoolSize(int size) {
    if (executorService instanceof ThreadPoolExecutor) {
        ThreadPoolExecutor pool = (ThreadPoolExecutor) executorService;
        pool.setCorePoolSize(size);
        pool.setMaximumPoolSize(size);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:8,代码来源:OtterController.java

示例10: fireServerAttributeUpdateEvent

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * Fire server attribute update event.
 *
 * @param source
 *         the source
 * @param attrs
 *         the config
 */
protected void fireServerAttributeUpdateEvent(JsfUrl source, Map<String, String> attrs) {
    LOGGER.info("Get server attribute update callback event, source: {}, data: {}", source, attrs);
    if (CommonUtils.isNotEmpty(attrs)) { // 需要区分alias
        try {
            int port = Integer.parseInt(attrs.get("port"));
            ThreadPoolExecutor executor = BusinessPool.getBusinessPool(port);
            if (executor != null) {
                if (attrs.containsKey("core")) {
                    int coreNew = Integer.parseInt(attrs.get("core"));
                    if (coreNew != executor.getCorePoolSize()) {
                        LOGGER.info("Core pool size of business pool at port {} change from {} to {}",
                                new Object[]{port, executor.getCorePoolSize(), coreNew});
                        executor.setCorePoolSize(coreNew);
                    }
                }
                if (attrs.containsKey("max")) {
                    int maxNew = Integer.parseInt(attrs.get("max"));
                    if (maxNew != executor.getMaximumPoolSize()) {
                        LOGGER.info("Maximum pool size of business pool at port {} change from {} to {}",
                                new Object[]{port, executor.getMaximumPoolSize(), maxNew});
                        executor.setMaximumPoolSize(maxNew);
                    }
                }
            }
        } catch (Exception e) {
            LOGGER.warn("Fire server attribute update event error!", e);
        }
    }
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:38,代码来源:RegistryCallbackHandler.java

示例11: testGetMaximumPoolSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * getMaximumPoolSize returns value given in constructor if not
 * otherwise set
 */
public void testGetMaximumPoolSize() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(2, 3,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        assertEquals(3, p.getMaximumPoolSize());
        p.setMaximumPoolSize(5);
        assertEquals(5, p.getMaximumPoolSize());
        p.setMaximumPoolSize(4);
        assertEquals(4, p.getMaximumPoolSize());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ThreadPoolExecutorTest.java

示例12: testMaximumPoolSizeIllegalArgumentException

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setMaximumPoolSize(int) throws IllegalArgumentException if
 * given a value less the core pool size
 */
public void testMaximumPoolSizeIllegalArgumentException() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(2, 3,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        try {
            p.setMaximumPoolSize(1);
            shouldThrow();
        } catch (IllegalArgumentException success) {}
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ThreadPoolExecutorTest.java

示例13: testMaximumPoolSizeIllegalArgumentException2

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setMaximumPoolSize throws IllegalArgumentException
 * if given a negative value
 */
public void testMaximumPoolSizeIllegalArgumentException2() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(2, 3,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        try {
            p.setMaximumPoolSize(-1);
            shouldThrow();
        } catch (IllegalArgumentException success) {}
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ThreadPoolExecutorTest.java

示例14: testGetMaximumPoolSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * getMaximumPoolSize returns value given in constructor if not
 * otherwise set
 */
public void testGetMaximumPoolSize() {
    final ThreadPoolExecutor p =
        new CustomTPE(2, 3,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        assertEquals(3, p.getMaximumPoolSize());
        p.setMaximumPoolSize(5);
        assertEquals(5, p.getMaximumPoolSize());
        p.setMaximumPoolSize(4);
        assertEquals(4, p.getMaximumPoolSize());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ThreadPoolExecutorSubclassTest.java

示例15: testMaximumPoolSizeIllegalArgumentException

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setMaximumPoolSize(int) throws IllegalArgumentException
 * if given a value less the core pool size
 */
public void testMaximumPoolSizeIllegalArgumentException() {
    final ThreadPoolExecutor p =
        new CustomTPE(2, 3,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        try {
            p.setMaximumPoolSize(1);
            shouldThrow();
        } catch (IllegalArgumentException success) {}
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ThreadPoolExecutorSubclassTest.java


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