关于spring 线程池

spring 线程池ThreadPoolTaskExecutor 

<bean id ="taskExecutor"  class ="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" >  

    <!-- 线程池维护线程的最少数量 -->  

<property name ="corePoolSize" value ="5" />  

    <!-- 线程池维护线程所允许的空闲时间 -->  

<property name ="keepAliveSeconds" value ="30000" />  

    <!-- 线程池维护线程的最大数量 -->  

<property name ="maxPoolSize" value ="1000" />  

    <!-- 缓冲队列 -->  

<property name ="queueCapacity" value ="200" /> 

 

 

ThreadPoolTaskExecutor poolTaskExecutor = (ThreadPoolTaskExecutor)contex.getBean("taskExecutor");

 

利用线程池启动线程

Thread myThread = new Thread(myRunnable);

poolTaskExecutor.execute(myThread);

获取当前线程池活动的线程数:

int count = poolTaskExecutor.getActiveCount();

惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶惊讶

Spring 里的mergePropertiesIntoMap 方法:

 mergePropertiesIntoMap(Properties props, Map map) {

if (map == null) {

throw new IllegalArgumentException("Map must not be null");

}

if (props != null) {

for (Enumeration en = props.propertyNames(); en.hasMoreElements();) {

String key = (String) en.nextElement();

Object value = props.getProperty(key);

if (value == null) {

// Potentially a non-String value...

value = props.get(key);

}

map.put(key, value);

}

}

}

 

props 是一个Properties 的实例 (其实Properties相当于一个 key 和value 都是String 类型 的Map而已), for (Enumeration en = props.propertyNames(); en.hasMoreElements();) { }   如此遍历map 好高级哦,

Methods are provided to enumerate through the elements of a vector, the keys of a hashtable, and the values in a hashtable. Enumerations are also used to specify the input streams to a SequenceInputStream.

 

 但是叫喊 -------〉

NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.

 

吻吻吻吻吻吻吻吻吻吻吻吻吻吻吻吻吻吻吻

Hashtable  environment1;

 

@Test

public void testClone() throws Exception {

   environment1 = new Hashtable<String, Integer>(2);

environment1.put("one", 1);

environment1.put("two", 2);

 

this.testInitialContext(environment1);

 

}

 

public void testInitialContext(Hashtable<?,?> environment) throws NamingException

   {

       if (environment != null) {

           environment = (Hashtable)environment.clone();//这样保证我们 在function testInitialContext中的操作不改变原始的environment. BUT: the keys and values are not cloned. This is a relatively expensive operation.

           environment.remove("one");

           if(environment1==environment){

           System.out.println("........why clone?");

           }

       }

   }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值