| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1 @@ | |||
| 1 | - language: java # 构建语言 | ||
| 2 | - | ||
| 3 | - sudo: false # 开启基于容器的Travis CI任务,让编译效率更高。 | ||
| 4 | - | ||
| 5 | - dist: precise | ||
| 6 | - | ||
| 7 | - notifications: # 每次构建的时候是否通知,如果不想收到通知邮箱(个人感觉邮件贼烦),那就设置false吧 | ||
| 8 | - email: false | ||
| 9 | - | ||
| 10 | - jdk: | ||
| 11 | - - oraclejdk8 | ||
| 1 | + language: java | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,6 @@ http://localhost:808/doc.html bootstrap-ui | |||
| 65 | 65 | - 2017-11-03 添加kotlin环境配置 | |
| 66 | 66 | - 2017-11-03 按照阿里巴巴编程规范插件P3C优化代码 | |
| 67 | 67 | - 2017-11-03 合并`api`和`website`模块,访问`localhost:8080`会显示网站主页,访问`localhost:8080/api`会显示api管理界面 | |
| 68 | - - 2017-11-03 从java代码转移到kotlin上(java版本请选择[v2017.1](https://github.com/xiaomoinfo/SpringBootUnity/tree/2017.1)) | ||
| 69 | 68 | ||
| 70 | 69 | ||
| 71 | 70 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,6 @@ | |||
| 23 | 23 | <plugin> | |
| 24 | 24 | <groupId>org.springframework.boot</groupId> | |
| 25 | 25 | <artifactId>spring-boot-maven-plugin</artifactId> | |
| 26 | - <version>1.5.8.RELEASE</version> | ||
| 27 | 26 | <executions> | |
| 28 | 27 | <execution> | |
| 29 | 28 | <goals> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,13 @@ | |||
| 1 | - package info.xiaomo.anysc | ||
| 1 | + package info.xiaomo.anysc; | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | - import org.springframework.boot.SpringApplication | ||
| 5 | - import org.springframework.boot.autoconfigure.EnableAutoConfiguration | ||
| 6 | - import org.springframework.boot.autoconfigure.domain.EntityScan | ||
| 7 | - import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration | ||
| 8 | - import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration | ||
| 9 | - import org.springframework.context.annotation.ComponentScan | ||
| 4 | + import org.springframework.boot.SpringApplication; | ||
| 5 | + import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| 6 | + import org.springframework.boot.autoconfigure.domain.EntityScan; | ||
| 7 | + import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
| 8 | + import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; | ||
| 9 | + import org.springframework.context.annotation.ComponentScan; | ||
| 10 | + import org.springframework.context.annotation.Configuration; | ||
| 10 | 11 | ||
| 11 | 12 | /** | |
| 12 | 13 | * 把今天最好的表现当作明天最新的起点..~ | |
@@ -17,16 +18,18 @@ | |||
| 17 | 18 | * @author : xiaomo | |
| 18 | 19 | * github: https://github.com/xiaomoinfo | |
| 19 | 20 | * email: xiaomo@xiaomo.info | |
| 20 | - * | ||
| 21 | + * <p> | ||
| 21 | 22 | * Date: 2016/4/1 15:38 | |
| 22 | 23 | * Description: RabbitMq启动器 | |
| 23 | 24 | * Copyright(©) 2015 by xiaomo. | |
| 24 | - */ | ||
| 25 | - @EnableAutoConfiguration(exclude = arrayOf(DataSourceAutoConfiguration::class, HibernateJpaAutoConfiguration::class)) | ||
| 25 | + **/ | ||
| 26 | + @Configuration | ||
| 27 | + @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) | ||
| 26 | 28 | @ComponentScan("info.xiaomo") | |
| 27 | 29 | @EntityScan("info.xiaomo.*.model") | |
| 28 | - class AsyncMain | ||
| 30 | + public class AsyncMain { | ||
| 31 | + public static void main(String[] args) throws Exception { | ||
| 32 | + SpringApplication.run(AsyncMain.class, args); | ||
| 33 | + } | ||
| 29 | 34 | ||
| 30 | - fun main(args: Array<String>) { | ||
| 31 | - SpringApplication.run(AsyncMain::class, *args) | ||
| 32 | 35 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,160 @@ | |||
| 1 | + package info.xiaomo.anysc.controller; | ||
| 2 | + | ||
| 3 | + import info.xiaomo.anysc.task.AsyncTask; | ||
| 4 | + import info.xiaomo.core.base.BaseController; | ||
| 5 | + import info.xiaomo.core.base.Result; | ||
| 6 | + import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | + import org.springframework.data.domain.Page; | ||
| 8 | + import org.springframework.web.bind.annotation.*; | ||
| 9 | + | ||
| 10 | + import java.util.List; | ||
| 11 | + import java.util.concurrent.Future; | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 把今天最好的表现当作明天最新的起点..~ | ||
| 15 | + * いま 最高の表現 として 明日最新の始発..~ | ||
| 16 | + * Today the best performance as tomorrow newest starter! | ||
| 17 | + * Created by IntelliJ IDEA. | ||
| 18 | + * | ||
| 19 | + * @author : xiaomo | ||
| 20 | + * github: https://github.com/xiaomoinfo | ||
| 21 | + * email: xiaomo@xiaomo.info | ||
| 22 | + * <p> | ||
| 23 | + * Date: 2016/11/15 15:12 | ||
| 24 | + * Description: 用户实体类 | ||
| 25 | + * Copyright(©) 2015 by xiaomo. | ||
| 26 | + **/ | ||
| 27 | + | ||
| 28 | + @RestController | ||
| 29 | + @RequestMapping("/") | ||
| 30 | + public class TestController extends BaseController { | ||
| 31 | + | ||
| 32 | + private final AsyncTask task; | ||
| 33 | + | ||
| 34 | + @Autowired | ||
| 35 | + public TestController(AsyncTask task) { | ||
| 36 | + this.task = task; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @RequestMapping(value = "/", method = RequestMethod.GET) | ||
| 40 | + public Result task() throws Exception { | ||
| 41 | + long start = System.currentTimeMillis(); | ||
| 42 | + | ||
| 43 | + Future<String> task1 = task.doTaskOne(); | ||
| 44 | + Future<String> task2 = task.doTaskTwo(); | ||
| 45 | + Future<String> task3 = task.doTaskThree(); | ||
| 46 | + | ||
| 47 | + while (true) { | ||
| 48 | + if (task1.isDone() && task2.isDone() && task3.isDone()) { | ||
| 49 | + // 三个任务都调用完成,退出循环等待 | ||
| 50 | + break; | ||
| 51 | + } | ||
| 52 | + Thread.sleep(1000); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + long end = System.currentTimeMillis(); | ||
| 56 | + | ||
| 57 | + System.out.println("任务全部完成,总耗时:" + (end - start) + "毫秒"); | ||
| 58 | + return new Result<>(end - start); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 查找所有(不带分页) | ||
| 64 | + * | ||
| 65 | + * @return result | ||
| 66 | + */ | ||
| 67 | + @Override | ||
| 68 | + public Result<List> findAll() { | ||
| 69 | + return null; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 带分页 | ||
| 74 | + * | ||
| 75 | + * @param start 起始页 | ||
| 76 | + * @param pageSize 页码数 | ||
| 77 | + * @return result | ||
| 78 | + */ | ||
| 79 | + @Override | ||
| 80 | + public Result<Page> findAll(@PathVariable int start, @PathVariable int pageSize) { | ||
| 81 | + return null; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 根据id查看模型 | ||
| 86 | + * | ||
| 87 | + * @param id id | ||
| 88 | + * @return result | ||
| 89 | + */ | ||
| 90 | + @Override | ||
| 91 | + public Result findById(@PathVariable Long id) { | ||
| 92 | + return null; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 根据名字查找模型 | ||
| 97 | + * | ||
| 98 | + * @param name name | ||
| 99 | + * @return result | ||
| 100 | + */ | ||
| 101 | + @Override | ||
| 102 | + public Result findByName(@PathVariable String name) { | ||
| 103 | + return null; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + /** | ||
| 107 | + * 根据名字删除模型 | ||
| 108 | + * | ||
| 109 | + * @param name name | ||
| 110 | + * @return result | ||
| 111 | + */ | ||
| 112 | + @Override | ||
| 113 | + public Result<Boolean> delByName(@PathVariable String name) { | ||
| 114 | + return null; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * 根据id删除模型 | ||
| 119 | + * | ||
| 120 | + * @param id id | ||
| 121 | + * @return result | ||
| 122 | + */ | ||
| 123 | + @Override | ||
| 124 | + public Result<Boolean> delById(@PathVariable Long id) { | ||
| 125 | + return null; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * 添加模型 | ||
| 130 | + * | ||
| 131 | + * @param model model | ||
| 132 | + * @return result | ||
| 133 | + */ | ||
| 134 | + @Override | ||
| 135 | + public Result<Boolean> add(@RequestBody Object model) { | ||
| 136 | + return null; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * 更新 | ||
| 141 | + * | ||
| 142 | + * @param model model | ||
| 143 | + * @return result | ||
| 144 | + */ | ||
| 145 | + @Override | ||
| 146 | + public Result<Boolean> update(@RequestBody Object model) { | ||
| 147 | + return null; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + /** | ||
| 151 | + * 批量删除 | ||
| 152 | + * | ||
| 153 | + * @param ids ids | ||
| 154 | + * @return result | ||
| 155 | + */ | ||
| 156 | + @Override | ||
| 157 | + public Result<Boolean> delByIds(@PathVariable List ids) { | ||
| 158 | + return null; | ||
| 159 | + } | ||
| 160 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,48 @@ | |||
| 1 | + package info.xiaomo.anysc.task; | ||
| 2 | + | ||
| 3 | + import org.springframework.scheduling.annotation.Async; | ||
| 4 | + import org.springframework.scheduling.annotation.AsyncResult; | ||
| 5 | + import org.springframework.stereotype.Component; | ||
| 6 | + | ||
| 7 | + import java.util.Random; | ||
| 8 | + import java.util.concurrent.Future; | ||
| 9 | + | ||
| 10 | + /** | ||
| 11 | + * @author : xiaomo | ||
| 12 | + */ | ||
| 13 | + @Component | ||
| 14 | + public class AsyncTask { | ||
| 15 | + | ||
| 16 | + private static Random random = new Random(); | ||
| 17 | + | ||
| 18 | + @Async | ||
| 19 | + public Future<String> doTaskOne() throws Exception { | ||
| 20 | + System.out.println("开始做任务一"); | ||
| 21 | + long start = System.currentTimeMillis(); | ||
| 22 | + Thread.sleep(random.nextInt(10000)); | ||
| 23 | + long end = System.currentTimeMillis(); | ||
| 24 | + System.out.println("完成任务一,耗时:" + (end - start) + "毫秒"); | ||
| 25 | + return new AsyncResult<>("任务一完成"); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Async | ||
| 29 | + public Future<String> doTaskTwo() throws Exception { | ||
| 30 | + System.out.println("开始做任务二"); | ||
| 31 | + long start = System.currentTimeMillis(); | ||
| 32 | + Thread.sleep(random.nextInt(10000)); | ||
| 33 | + long end = System.currentTimeMillis(); | ||
| 34 | + System.out.println("完成任务二,耗时:" + (end - start) + "毫秒"); | ||
| 35 | + return new AsyncResult<>("任务二完成"); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + @Async | ||
| 39 | + public Future<String> doTaskThree() throws Exception { | ||
| 40 | + System.out.println("开始做任务三"); | ||
| 41 | + long start = System.currentTimeMillis(); | ||
| 42 | + Thread.sleep(random.nextInt(10000)); | ||
| 43 | + long end = System.currentTimeMillis(); | ||
| 44 | + System.out.println("完成任务三,耗时:" + (end - start) + "毫秒"); | ||
| 45 | + return new AsyncResult<>("任务三完成"); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments