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

申请的网站怎么建设wordpress 友情链接

申请的网站怎么建设,wordpress 友情链接,网站建设制作小程序开发,江苏省建设厅网站公示Spring多线程 Spring通过任务执行器(TaskExecutor)来实现多线程和并发编程ThreadPoolTaskExecutor实现一个基于线程池的TaskExecutor配置类中EnableAsync开启对异步任务的支持使用Async声明该任务为异步 ①、配置类 Configuration ComponentScan(&quo…

Spring多线程

  • Spring通过任务执行器(TaskExecutor)来实现多线程和并发编程
  • ThreadPoolTaskExecutor实现一个基于线程池的TaskExecutor
  • 配置类中@EnableAsync开启对异步任务的支持
  • 使用@Async声明该任务为异步

①、配置类

@Configuration
@ComponentScan("com.xxx.taskExecutor")
@EnableAsync //开启异步任务
public class TaskExecutorConfig implements AsyncConfigurer{//获取一个基于线程池的TaskExecutor@Overridepublic Executor getAsyncExecutor(){ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();taskExecutor.setCorePoolSize(5);taskExecutor.setMaxPoolSize(10);taskExecutor.setQueueCapacity(25);taskExecutor.initialize();return taskExecutor;}@Overridepubic AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler(){return null;}
}

②、任务执行类

这里的方法自动被注入使用ThreadPoolTaskExecutor作为TaskExecutor

@Service
public class AsyncTaskService{@Async //该方法是异步方法,如果注解到类上,标识该类所有方法都是异步的public void executeAsyncTask(Integer i){System.out.println("执行异步任务"+i);}@Asyncpublic void executeAsyncTaskPlus(Integer i){System.out.println("执行异步任务+1"+(i+1));}
}

③、运行

结果是并发执行,而不是顺序执行

public class Main{public static void main(String[] args){AnnotationConfigApplicationContext context = AnnotationConfigApplicationContext(TaskExecutorConfig.class);AsyncTaskService asyncTaskService = context.getBean(TaskExecutorConfig.class);for(int i = 0;i < 10;i++){asyncTaskService.executeAsyncTask(i);asyncTaskService.executeAsyncTaskPlus(i);}context.close();}
}

异步任务执行服务ExecutorService

任务的提交和任务的执行相分离

  • 执行服务封装了任务执行的细节(线程创建、关闭,任务调度)
  • 提交关注任务本身(提交任务、获取结果、取消任务)
public class BasicDemo{static class Task implements Callable<Integer>{int sleepSeconds = new Random().nextInt(1000);Thread.sleep(sleepSeconds);return sleepSeconds;}public static void main(String[] args){ExecutorService executor = Executors.newSingleThreadExecutor();Future<Integer> future = executor.submit(new Task());//模拟其他任务Thread.sleep(100);try{System.out.println(future.get());}catch(ExecutionException e){e.printStackTrace();}executor.shutdown();}
}

@Enable*注解

@EnableAspectJAutoProxy 开启对AspectJ自动代理的支持
@EnableAsync 开启异步方法的支持
@EnableScheduling 开启计划任务的支持

@EnableWebMvc 开启Web MVC的配置支持
@EnableConfigurationProperties开启对@ConfigurationProperties注解配置Bean的支持
@EnableJpaRepositories开启对Spring Data Repository的支持
@EnableTransactionManagement开启对注解式事务的支持
@EnableCaching开启注解式的缓存支持

以上所有开启功能的共性,都有一个@Import用来导入配置类

一、直接导入配置类

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(SchedulingConfiguration.class)//直接导入配置类
@Documented
public @interface EnableScheduling{}

二、依据条件选择配置类

@Target(ElementType.TYPE)
@Retention(RetentionPlicy.RUNTIME)
@Documented
@Import(AsyncConfigurationSelector.class)//通过条件来选择需要导入的
public @interface EnableAsync{Class<? extends Annotation> annotation() default Annotation.class;boolean proxyTargetClass() default false;AdviceMode mode() default AdviceMode.PROXY;int order() default Order.LOWEST_PRECEDENCE;
}

三、动态注册Bean

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(AspectJAutoProxyRegistrar.class)//运行时自动添加Bean到已有的配置类
public @interface EnableAspectJAutoProxy{boolean proxyTargetClass() default false;
}

Spring测试

Spring通过Spring TestContext Framework对集成测试提供顶级支持
不依赖特定框架,既可以用Junit,也可以用TestNG

Spring提供了一个SpringJUnit4ClassRunner类
该类提供了Spring TestContext Framework的功能,通过@ContextConfiguration来配置Application Context
通过@ActiveProfiles确定活动的profile

①、依赖

spring-test junit

②、业务代码

public class TestBean{private String content;public TestBean(String content){super();this.content = content;}public String getContent(){return content;}public void setContent(String content){this.content = content;}
}

③、配置类

@Configuration
public class TestConfig{@Bean@Profile("dev")public TestBean devTestBean(){return new TestBean("from development profile");}@Bean@Profile("prod")public TestBean prodTestBean(){return new TestBean("from production profile");}
}

④、测试```java
@RunWith(SpringJUnit4ClassRunner.class)//JUnit环境下提供Spring TestContext Framework的功能
@ContextConfiguration(classes = {TestConfig.class})//用来加载配置ApplicationContext其中classes属性用来加载配置类
@ActiveProfiles("prod")//用来声明活动的profile
public class DemoBeanIntegrationTests{@Autowiredprivate TestBean testBean;@Testpublic void prodBeanShouldInject(){String expected = "from production profile";String actual = testBean.getContent();Assert.assertEquals(expected,actual);}
}
http://www.yayakq.cn/news/890024/

相关文章:

  • 去哪儿网站做宣传多少钱山东泰安
  • 艺术学院网站建设管理办法注册公司网站模板
  • 网站建设自学企业信息网页模板
  • 长春专业做网站的公司建设网站的作用及意义
  • 汝州网站建设汝州专业的营销网站建设公司排名
  • 未备案网站 怎么处理手机必备网站
  • 技术支持 网站建设怎么注册wordpress账号
  • 湖北城市建设职业技术学院教务网站运营一个网站的成本
  • 中企动力做的网站容易SEO吗体育直播网站源码
  • 镇江门户网站是哪个定制wordpress后台
  • 长安网站建设哪家好WordPress5更改logo
  • 怎么制作自己的网页网站钻探公司宣传册设计样本
  • 天门网站网站建设建设部标准定额司网站
  • 网站开发和大数据开发区别wordpress 当前分类链接地址
  • 网站服务器有哪些浙江省建设协会网站
  • 公司网站建设合同模板下载短视频运营基础知识
  • asp 制作网站开发购物网站可行性分析报告
  • 安徽省建设部干部网站重庆农产品价格信息网
  • 关于网站开发的学校搜狐快站建站
  • 网站开发资源网做游戏网站用什么软件
  • jsp网站开发遇到的问题深圳做微信网站公司名称
  • 小区媒体网站建设wordpress主题和预览不同
  • 网站编辑简历做视频网站需要哪些技术指标
  • 高端网站建设kgu湖北做网站多少钱
  • 学平面设计网站搜狗收录批量查询
  • 网站的积分系统怎么做局域网建站软件
  • 做房产中介网站西部数码装wordpress
  • cms免费企业网站广州网页建站
  • 聊城网站那家做的好网站建设贵州
  • 网站怎么做图片放映效果做节约用水海报的网站