/**
 * 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
}

}

测试spring容器相关推荐

  1. spring配置数据源(交给spring容器完成)

    ##将DataSource的创建权交给spring容器去完成 1.导入spring依赖 <dependency><groupId>org.springframework< ...

  2. Spring第二弹—–搭建与测试Spring的开发环境

    PS:Spring既可以使用在javaSE中,也可以使用在javaWeb中. 使用Spring需要的jar 下载spring(我下载的是2.5.6版本),然后进行解压缩,在解压目录中找到下面jar文件 ...

  3. Spring笔记——2.使用Spring容器

    Spring有两个核心接口:BeanFactory和ApplicationContext.而ApplicationContext是BeanFactory的子接口,都可以代表Spring容器,用于产生管 ...

  4. Spring容器中Bean的作用域

    当通过Spring容器创建一个Bean实例时,不仅可以完成Bean实例的实例化,还可以为Bean指定特定的作用域.Spring支持如下5种作用域: singleton:单例模式,在整个Spring I ...

  5. 彻底理解 Spring 容器和应用上下文

    点击上方 好好学java ,选择 星标 公众号 重磅资讯.干货,第一时间送达 今日推荐:收藏了!7 个开源的 Spring Boot 前后端分离优质项目个人原创+1博客:点击前往,查看更多 作者:陈本 ...

  6. Spring容器中获取Bean实例的七种方式(附实战源码)

    目录 写作说明 一:写作原因 二:源码出处 实现方式 一:使用BeanFactory直接获取(不推荐) 二:在初始化时保存ApplicationContext对象 三:继承自抽象类Applicatio ...

  7. Spring容器与上下文理解

    2019独角兽企业重金招聘Python工程师标准>>> 转自:https://www.cnblogs.com/chenbenbuyi/p/8166304.html 个人感觉介绍的很不 ...

  8. 原始Junit测试Spring的问题

    在测试类中,每个测试方法都有以下两行代码: ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml" ...

  9. Spring基础篇——Spring容器和应用上下文理解

    转载自 https://www.cnblogs.com/chenbenbuyi/p/8166304.html 上文说到,有了Spring之后,通过依赖注入的方式,我们的业务代码不用自己管理关联对象的生 ...

最新文章

  1. 数据结构:二分查找 java
  2. 又在GitHub上挖到个宝藏:Switch模拟器!
  3. Linux 系统 文件锁 fcntl函数详解
  4. Redis list(列表)
  5. JS回调函数(callback)
  6. javascript 动态创建表格
  7. mysql dcn_Mysql varchar(max)
  8. 肯德基收银系统模式_肯德基的完整形式是什么?
  9. 分享-动态性能表详解
  10. 让form登录界面居中_徒手撸-登录页面(1)
  11. 全球闪存供应紧张 新iPhone涨价只是开始
  12. 曲线运动与万有引力公式_粤教版第三章第一节万有引力定律
  13. Architectures与指令集架构armv6,armv7,armv7s,arm64,i386,x86_64
  14. 统计学中sp_用excel和sp和ss学统计学.doc
  15. 什么是云计算,云计算运营方式和部署方式介绍
  16. Linux下文件压缩、打包,看这一篇就够了
  17. 1到100的和(C)
  18. 高分一号影像处理流程
  19. 语音智能小车:语音识别模块LD3320+STMF103
  20. VM虚拟机连接服务器

热门文章

  1. 如何在计算机左侧栏显示桌面,怎样在任务栏里加上“显示桌面”快捷键【图文教程】...
  2. 【读点论文】A Survey on Vision Transformer,2022年华为诺亚最新综述研究,从发展到任务,整体到局部。ViT有研究价值在于有很多问题还没有解决,真理是阶段性的产物
  3. 从360安全卫士卸载金山网盾看产品设计
  4. 大家快来尝尝鲜 转用 curl 和 scsh 编写 web 脚本(转)
  5. Opencv学习----位图(bitmap)原理详解三---位图解析度
  6. seo优化工具-免费SEO优化工具-站长SEO优化软件
  7. 互联网金融入门篇(二) 会计分录
  8. 面试操作系统问题及答案
  9. 投资新“鸡”遇,金鸡达人DAPP养鸡游戏震撼来袭
  10. Samsung Biologics采用Veeva Vault QMS来统一质量管理