当前位置: 首页 > news >正文

进口外贸流程无锡seo公司网站

进口外贸流程,无锡seo公司网站,全栈网站开发者,公司名字变了网站备案Springboot对多线程的支持详解这两天看阿里的JAVA开发手册#xff0c;到多线程的时候说永远不要用 new Thread()这种方式来使用多线程。确实是这样的#xff0c;我一直在用线程池#xff0c;到了springboot才发现他已经给我们提供了很方便的线程池机制。本博客代码托管在git…Springboot对多线程的支持详解这两天看阿里的JAVA开发手册到多线程的时候说永远不要用 new Thread()这种方式来使用多线程。确实是这样的我一直在用线程池到了springboot才发现他已经给我们提供了很方便的线程池机制。本博客代码托管在github上https://github.com/gxz0422042...一、介绍Spring是通过任务执行器(TaskExecutor)来实现多线程和并发编程使用ThreadPoolTaskExecutor来创建一个基于线城池的TaskExecutor。在使用线程池的大多数情况下都是异步非阻塞的。我们配置注解EnableAsync可以开启异步任务。然后在实际执行的方法上配置注解Async上声明是异步任务。二、配置类配置类代码如下package com.spartajet.springbootlearn.thread;import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;import org.springframework.context.annotation.Configuration;import org.springframework.scheduling.annotation.AsyncConfigurer;import org.springframework.scheduling.annotation.EnableAsync;import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;import java.util.concurrent.Executor;/*** description* create 2017-02-22 下午11:53* email gxz04220427163.com*/ConfigurationEnableAsyncpublic class ThreadConfig implements AsyncConfigurer {/*** The {link Executor} instance to be used when processing async* method invocations.*/Overridepublic Executor getAsyncExecutor() {ThreadPoolTaskExecutor executor new ThreadPoolTaskExecutor();executor.setCorePoolSize(5);executor.setMaxPoolSize(15);executor.setQueueCapacity(25);executor.initialize();return executor;}/*** The {link AsyncUncaughtExceptionHandler} instance to be used* when an exception is thrown during an asynchronous method execution* with {code void} return type.*/Overridepublic AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {return null;}}解读利用EnableAsync来开启Springboot对于异步任务的支持配置类实现接口AsyncConfigurator返回一个ThreadPoolTaskExecutor线程池对象。三、任务执行任务执行代码package com.spartajet.springbootlearn.thread;import org.springframework.scheduling.annotation.Async;import org.springframework.stereotype.Service;/*** description* create 2017-02-23 上午12:00* email gxz04220427163.com*/Servicepublic class AsyncTaskService {Asyncpublic void executeAsyncTask(int i) {System.out.println(线程 Thread.currentThread().getName() 执行异步任务 i);}}代码解读通过Async注解表明该方法是异步方法如果注解在类上那表明这个类里面的所有方法都是异步的。四、测试代码package com.spartajet.springbootlearn;import com.spartajet.springbootlearn.thread.AsyncTaskService;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;RunWith (SpringRunner.class)SpringBootTestpublic class SpringbootLearnApplicationTests {Autowiredprivate AsyncTaskService asyncTaskService;Testpublic void contextLoads() {}Testpublic void threadTest() {for (int i 0; i 20; i) {asyncTaskService.executeAsyncTask(i);}}}测试结果线程ThreadPoolTaskExecutor-4 执行异步任务3线程ThreadPoolTaskExecutor-2 执行异步任务1线程ThreadPoolTaskExecutor-1 执行异步任务0线程ThreadPoolTaskExecutor-1 执行异步任务7线程ThreadPoolTaskExecutor-1 执行异步任务8线程ThreadPoolTaskExecutor-1 执行异步任务9线程ThreadPoolTaskExecutor-1 执行异步任务10线程ThreadPoolTaskExecutor-5 执行异步任务4线程ThreadPoolTaskExecutor-3 执行异步任务2线程ThreadPoolTaskExecutor-5 执行异步任务12线程ThreadPoolTaskExecutor-1 执行异步任务11线程ThreadPoolTaskExecutor-2 执行异步任务6线程ThreadPoolTaskExecutor-4 执行异步任务5线程ThreadPoolTaskExecutor-2 执行异步任务16线程ThreadPoolTaskExecutor-1 执行异步任务15线程ThreadPoolTaskExecutor-5 执行异步任务14线程ThreadPoolTaskExecutor-3 执行异步任务13线程ThreadPoolTaskExecutor-1 执行异步任务19线程ThreadPoolTaskExecutor-2 执行异步任务18线程ThreadPoolTaskExecutor-4 执行异步任务17
http://wiki.neutronadmin.com/news/280669/

相关文章:

  • 公司建设网站怎么做账微信微网站建设平台
  • 网站建设 制作教程 pdf求个网站好人一生平安
  • 建立网站的准备工作南京模板建站哪家好
  • 杭州建设工程交易中心网站微信公众号怎样发布wordpress
  • 利用js做简单的网站iis默认网站删除
  • 做盗版电影网站手机网页设计网站建设
  • 做旅游业务的商业网站使用flashfxp上传网站
  • 中国最牛的央企排名安卓优化大师官网下载
  • 企业网站推广解决方案有没有免费的写文案的软件
  • 淘宝网站建设的详细策划wordpress 登录链接
  • h5哪个网站可以做1688做网站难吗
  • 杭州网站商场开发户外产品销售公司网站建设
  • 公司网站建设方案详细方案大型购物网站建设费用
  • 南宁网站建设速成培训班浙江网站设计公司
  • 家具网站建设规划书无极招聘信息网
  • 网站建设与推广的销售北京做网站的公司拟
  • 建设银行官网首页网站购纪念币ueditor for wordpress
  • 免费的网站推广重庆网站建设坤思特
  • 网站价值 批量查询花生壳免费域名注册
  • 东盟建设投资有限公司网站顺企网怎么样
  • 网站建设需要经过哪几个步骤关键词优化推广策略
  • 基层建设检索网站wordpress文章密码爆破
  • 网站栏目类型做网站用什么颜色好
  • 公司网站建设服务机构wordpress 手机 重定向 子目录
  • 做网站要注意哪些企业网站开发环境
  • 推荐网站建设服务器wordpress qq登入设置
  • 做百度移动端网站软件下载舟山网站建设开发
  • 专做眼镜的网站建设厅官方网站
  • 官网网站怎么做wordpress主题 可爱
  • 外贸网站建设浩森宇特wordpress邮件发文章