當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。