/**
 * 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. aliyun oss 文件上传 java.net.SocketTimeoutException Read timed out 问题分析及解决
  2. springmvc 音频流输出_音频管理模块AudioDeviceModule解读
  3. Java爬虫模拟登录——不给我毛概二的H某大学
  4. VMware ESXi 6.7服务器设置开机自动启动虚拟机
  5. 算法改进有多快?是否比迭代硬件收益更大?这是MIT的结论
  6. systemctl与mysql多实例_mysql mariadb 多版本多实例 开机启动
  7. Java-用户交互Scanner
  8. springboot配置多项目下统一切换不同环境变量profile办法
  9. c++ error函数_Linux中create_elf_tables函数整型溢出漏洞分析(CVE201814634)
  10. protoc 命令 java_用proto命令生成java文件
  11. 无人深空java修改器,无人深空next存档修改-无人深空next存档修改器下载v1.5.0最新版-西西软件下载...
  12. mfc入门基础(三)创建对话框
  13. c 上传文件路劲为服务器路径,获取上传文件的路径变成C:\fakepath\
  14. [计算机数值分析]牛顿插值公式
  15. HTML 拖放功能 - DragDrop
  16. 基于STM32C8T6的MLX90614-DCC红外无线测温系统
  17. /etc/security/limits.conf 详解与配置
  18. 华为HarmonyOS系统搭载了POKERTIME129263和AOMAHA的汉印智能打印新升级
  19. Linux 查看tomcat占用的端口号
  20. matlab怎么求三次微分,matlab课设三阶微分方程多种方法求解.doc

热门文章

  1. 手机同声传译软件有哪些?这里有你想知道的答案
  2. 机械键盘的轴-是一种分类方式
  3. LED灯上的ASEMI整流桥MB10F怎么检测是否正常
  4. 操作系统笔记第六章【输入输出系统】
  5. [资源汇总] 85个PACS精华资源汇总【2010年HC3i年终盘点】
  6. 常见的英文单词纠错法...
  7. 宝宝巴士冲刺上市背后:被指存在抄袭行为,顺为等股东提前退出
  8. OpenGL基础图形编程(十)真实感图形基本概念
  9. Springboot pox.xml 报错解决两种方式
  10. 计算机组成原理(六)-浮点数存储和浮点数计算