测试spring容器

/**
 * 2017年11月13日下午7:14:42
   aop-uc-internet
 */
package com.casic.test;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;


import javax.annotation.Resource;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


import com.casic.tenant.model.TenantInfo;
import com.hotent.core.util.UniqueIdUtil;
import com.hotent.platform.model.system.SysOrgInfo;
import com.hotent.platform.service.system.SysOrgInfoService;
import com.hotent.platform.service.system.SysUserService;




/**
 * @author Administrator
 *TestThread$
 */
@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试  
@ContextConfiguration(locations={"classpath*:conf/app-context.xml"}) //加载配置文件
public class TestThread {


@Resource
private SysUserService sysUserService;

@Test
public void test1(){

//ExecutorService fixedThreadPool = Executors.newFixedThreadPool(4);
ExecutorService fixedThreadPool = Executors.newCachedThreadPool();
ArrayList<Future<Resources>> FutureList = new ArrayList<Future<Resources>>();
for ( int j = 0; j < 33000; j++) {
Future<Resources> future = fixedThreadPool.submit(new Callable<Resources>() {
@Override
public Resources call() throws Exception {
long currentTimeMillis = System.currentTimeMillis();
String name = Thread.currentThread().getName();
System.out.println("开始时间:"+currentTimeMillis+"---"+name+"---开始工作了。。。。。。。。。。。。。。。。。。");
synchronized (TestThread.class) {
TenantInfo sysOrgInfo=new TenantInfo();
Random random=new Random();
int i=  random.nextInt(20000000);

sysOrgInfo.setSysOrgInfoId(Long.parseLong("740117"+13+i));
sysOrgInfo.setName("11王树民企业");
sysUserService.registerSysOrgAndUser(sysOrgInfo, "1223");
}
Resources resource2 = new Resources();
resource2.setResourceName("结束时间:"+currentTimeMillis+""+name+"---结束工作了。。。。。。。完成的任务号:{ }"+resource2.getTotal()+"。。。。。。。。");
return resource2;

}
});
FutureList.add(future);

}

for (Future<Resources> future2 : FutureList) {

if(true){
try {

Resources resource = future2.get();
boolean done = future2.isDone();
System.out.println("done:"+done);
System.out.println("返回結果"+resource.getResourceName());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}

}

}
}


}






class Resources implements Serializable{

private  String  ResourceName;
private int  total;
/**
* @return the resourceName
*/
protected String getResourceName() {
return ResourceName;
}
/**
* @param resourceName the resourceName to set
*/
protected void setResourceName(String resourceName) {
ResourceName = resourceName;
}
/**
* @return the total
*/
protected int getTotal() {
return total;
}
/**
* @param total the total to set
*/
protected void setTotal(int total) {
this.total = total;
}
@Override
public String toString() {
return "Resource [ResourceName=" + ResourceName + ", total=" + total
+ "]";
}
/**
* @param resourceName
* @param total
*/
public Resources(String resourceName, int total) {
super();
ResourceName = resourceName;
this.total = total;
}
/**

*/
public Resources() {
// TODO Auto-generated constructor stub
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值