本文整理了Java中java.lang.Runtime.availableProcessors()
方法的一些代码示例,展示了Runtime.availableProcessors()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Runtime.availableProcessors()
方法的具体详情如下:
包路径:java.lang.Runtime
类名称:Runtime
方法名:availableProcessors
[英]Returns the number of processor cores available to the VM, at least 1. Traditionally this returned the number currently online, but many mobile devices are able to take unused cores offline to save power, so releases newer than Android 4.2 (Jelly Bean) return the maximum number of cores that could be made available if there were no power or heat constraints.
[中]返回VM可用的处理器内核数,至少1个。传统上,这返回了当前在线的数量,但许多移动设备能够将未使用的内核脱机以节省电源,因此比Android 4.2(Jelly Bean)更新的版本返回了在没有电源或热量限制的情况下可用的最大内核数。
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new {@code Netty4ClientHttpRequestFactory} with a default
* {@link NioEventLoopGroup}.
*/
public Netty4ClientHttpRequestFactory() {
int ioWorkerCount = Runtime.getRuntime().availableProcessors() * 2;
this.eventLoopGroup = new NioEventLoopGroup(ioWorkerCount);
this.defaultEventLoopGroup = true;
}
代码示例来源:origin: hankcs/HanLP
/**
* 开启多线程
* @param enable true表示开启[系统CPU核心数]个线程,false表示单线程
* @return
*/
public Segment enableMultithreading(boolean enable)
{
if (enable) config.threadNumber = Runtime.getRuntime().availableProcessors();
else config.threadNumber = 1;
return this;
}
代码示例来源:origin: stackoverflow.com
int cores = Runtime.getRuntime().availableProcessors();
代码示例来源:origin: stackoverflow.com
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
private static final BlockingQueue<Runnable> sPoolWorkQueue =
new LinkedBlockingQueue<Runnable>(128);
代码示例来源:origin: redisson/redisson
public LRUCacheMap(int size, long timeToLiveInMillis, long maxIdleInMillis) {
super(size, timeToLiveInMillis, maxIdleInMillis);
for (int i = 0; i < Runtime.getRuntime().availableProcessors()*2; i++) {
Set<CachedValue<K, V>> instance = Collections.synchronizedSet(new LinkedHashSet<CachedValue<K, V>>());
queues.add(instance);
}
}
代码示例来源:origin: bumptech/glide
/**
* Determines the number of cores available on the device.
*/
static int availableProcessors() {
int cpus = Runtime.getRuntime().availableProcessors();
if (Build.VERSION.SDK_INT < 17) {
cpus = Math.max(getCoreCountPre17(), cpus);
}
return cpus;
}
代码示例来源:origin: hankcs/HanLP
@Override
public Result train(String trainingFile, String developFile, String modelFile) throws IOException
{
// 词性标注模型压缩会显著降低效果
return train(trainingFile, developFile, modelFile, 0, 10, Runtime.getRuntime().availableProcessors());
}
}
代码示例来源:origin: hankcs/HanLP
public Result train(String trainingFile, String developFile, String modelFile) throws IOException
{
return train(trainingFile, developFile, modelFile, 0.1, 50, Runtime.getRuntime().availableProcessors());
}
代码示例来源:origin: prestodb/presto
@Inject
public IndexLookup(Connector connector, ColumnCardinalityCache cardinalityCache)
{
this.connector = requireNonNull(connector, "connector is null");
this.cardinalityCache = requireNonNull(cardinalityCache, "cardinalityCache is null");
// Create a bounded executor with a pool size at 4x number of processors
this.coreExecutor = newCachedThreadPool(daemonThreadsNamed("cardinality-lookup-%s"));
this.executorService = new BoundedExecutor(coreExecutor, 4 * Runtime.getRuntime().availableProcessors());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new {@code TaskExecutorRegistration} for a default
* {@link ThreadPoolTaskExecutor}.
*/
public TaskExecutorRegistration() {
this.taskExecutor = new ThreadPoolTaskExecutor();
this.taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
this.taskExecutor.setAllowCoreThreadTimeOut(true);
}
代码示例来源:origin: spring-projects/spring-framework
@Bean(name = {"messageBrokerTaskScheduler", "messageBrokerSockJsTaskScheduler"})
public ThreadPoolTaskScheduler messageBrokerTaskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setThreadNamePrefix("MessageBroker-");
scheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
scheduler.setRemoveOnCancelPolicy(true);
return scheduler;
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Take a Publisher and prepare to consume it on multiple 'rails' (number of CPUs)
* in a round-robin fashion.
* @param <T> the value type
* @param source the source Publisher
* @return the ParallelFlowable instance
*/
@CheckReturnValue
public static <T> ParallelFlowable<T> from(@NonNull Publisher<? extends T> source) {
return from(source, Runtime.getRuntime().availableProcessors(), Flowable.bufferSize());
}
代码示例来源:origin: spring-projects/spring-framework
public static RuntimeBeanReference registerScheduler(
String schedulerName, ParserContext context, @Nullable Object source) {
if (!context.getRegistry().containsBeanDefinition(schedulerName)) {
RootBeanDefinition taskSchedulerDef = new RootBeanDefinition(ThreadPoolTaskScheduler.class);
taskSchedulerDef.setSource(source);
taskSchedulerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
taskSchedulerDef.getPropertyValues().add("poolSize", Runtime.getRuntime().availableProcessors());
taskSchedulerDef.getPropertyValues().add("threadNamePrefix", schedulerName + "-");
taskSchedulerDef.getPropertyValues().add("removeOnCancelPolicy", true);
context.getRegistry().registerBeanDefinition(schedulerName, taskSchedulerDef);
context.registerComponent(new BeanComponentDefinition(taskSchedulerDef, schedulerName));
}
return new RuntimeBeanReference(schedulerName);
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private RootBeanDefinition getDefaultExecutorBeanDefinition(String channelName) {
if (channelName.equals("brokerChannel")) {
return null;
}
RootBeanDefinition executorDef = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
executorDef.getPropertyValues().add("corePoolSize", Runtime.getRuntime().availableProcessors() * 2);
executorDef.getPropertyValues().add("maxPoolSize", Integer.MAX_VALUE);
executorDef.getPropertyValues().add("queueCapacity", Integer.MAX_VALUE);
executorDef.getPropertyValues().add("allowCoreThreadTimeOut", true);
return executorDef;
}
代码示例来源:origin: redisson/redisson
/**
* Take a Publisher and prepare to consume it on multiple 'rails' (number of CPUs)
* in a round-robin fashion.
* @param <T> the value type
* @param source the source Publisher
* @return the ParallelFlowable instance
*/
@CheckReturnValue
public static <T> ParallelFlowable<T> from(@NonNull Publisher<? extends T> source) {
return from(source, Runtime.getRuntime().availableProcessors(), Flowable.bufferSize());
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-11623
public void customChannelsWithDefaultExecutor() {
loadBeanDefinitions("websocket-config-broker-customchannels-default-executor.xml");
testExecutor("clientInboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
testExecutor("clientOutboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
assertFalse(this.appContext.containsBean("brokerChannelExecutor"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void threadPoolSizeDefault() {
ApplicationContext context = loadConfig(DefaultConfig.class);
String name = "clientInboundChannelExecutor";
ThreadPoolTaskExecutor executor = context.getBean(name, ThreadPoolTaskExecutor.class);
assertEquals(Runtime.getRuntime().availableProcessors() * 2, executor.getCorePoolSize());
// No way to verify queue capacity
name = "clientOutboundChannelExecutor";
executor = context.getBean(name, ThreadPoolTaskExecutor.class);
assertEquals(Runtime.getRuntime().availableProcessors() * 2, executor.getCorePoolSize());
name = "brokerChannelExecutor";
executor = context.getBean(name, ThreadPoolTaskExecutor.class);
assertEquals(0, executor.getCorePoolSize());
assertEquals(1, executor.getMaxPoolSize());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void taskScheduler() {
ApplicationContext config = createConfig(TestChannelConfig.class, TestConfigurer.class);
String name = "messageBrokerSockJsTaskScheduler";
ThreadPoolTaskScheduler taskScheduler = config.getBean(name, ThreadPoolTaskScheduler.class);
ScheduledThreadPoolExecutor executor = taskScheduler.getScheduledThreadPoolExecutor();
assertEquals(Runtime.getRuntime().availableProcessors(), executor.getCorePoolSize());
assertTrue(executor.getRemoveOnCancelPolicy());
SimpleBrokerMessageHandler handler = config.getBean(SimpleBrokerMessageHandler.class);
assertNotNull(handler.getTaskScheduler());
assertArrayEquals(new long[] {15000, 15000}, handler.getHeartbeatValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void reduceFull() {
for (int i = 1; i <= Runtime.getRuntime().availableProcessors() * 2; i++) {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
Flowable.range(1, 10)
.parallel(i)
.reduce(new BiFunction<Integer, Integer, Integer>() {
@Override
public Integer apply(Integer a, Integer b) throws Exception {
return a + b;
}
})
.subscribe(ts);
ts.assertResult(55);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setup() {
this.executor = new ThreadPoolTaskExecutor();
this.executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
this.executor.setAllowCoreThreadTimeOut(true);
this.executor.afterPropertiesSet();
this.channel = new ExecutorSubscribableChannel(this.executor);
OrderedMessageSender.configureOutboundChannel(this.channel, true);
this.sender = new OrderedMessageSender(this.channel, logger);
}
内容来源于网络,如有侵权,请联系作者删除!