Commit 0a1f7fb4abfbc4bfcb2bd6d0cbbbcbd6e12f67c3
1 parent
03abb4ae
1.GpsCacheData中HashMap替换成并发Map
# Conflicts: # src/main/java/com/bsth/data/gpsdata_v2/DataHandleProcess.java
Showing
1 changed file
with
3 additions
and
58 deletions
src/main/java/com/bsth/data/gpsdata_v2/DataHandleProcess.java
| ... | ... | @@ -41,27 +41,13 @@ public class DataHandleProcess { |
| 41 | 41 | ReverseRouteProcess reverseRouteProcess; |
| 42 | 42 | @Autowired |
| 43 | 43 | GpsRealData gpsRealData; |
| 44 | - // 发送邮件 | |
| 45 | - @Autowired | |
| 46 | - private SendEmailController sendEmailController; | |
| 47 | 44 | |
| 48 | 45 | |
| 49 | 46 | static Logger logger = LoggerFactory.getLogger(DataHandleProcess.class); |
| 50 | 47 | |
| 51 | 48 | final static int POOL_SIZE = 20; |
| 52 | 49 | |
| 53 | - static ExecutorService threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1, new ThreadFactory() { | |
| 54 | - | |
| 55 | - @Override | |
| 56 | - public Thread newThread(Runnable r) { | |
| 57 | - // TODO Auto-generated method stub | |
| 58 | - Thread t = new Thread(r); | |
| 59 | - t.setName("GPSProcessor"); | |
| 60 | - | |
| 61 | - return t; | |
| 62 | - } | |
| 63 | - | |
| 64 | - }); | |
| 50 | + static ExecutorService threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1); | |
| 65 | 51 | public static CountDownLatch count; |
| 66 | 52 | |
| 67 | 53 | static long lastTime; |
| ... | ... | @@ -69,22 +55,7 @@ public class DataHandleProcess { |
| 69 | 55 | public static boolean isBlock() { |
| 70 | 56 | return System.currentTimeMillis() - lastTime > 1000 * 30; |
| 71 | 57 | } |
| 72 | - | |
| 73 | - private void shutdownAndAwaitTermination(ExecutorService pool) { | |
| 74 | - pool.shutdown(); | |
| 75 | - try { | |
| 76 | - if (!pool.awaitTermination(500, TimeUnit.MILLISECONDS)) { | |
| 77 | - pool.shutdownNow(); | |
| 78 | - } | |
| 79 | - if (!pool.awaitTermination(500, TimeUnit.MILLISECONDS)) { | |
| 80 | - logger.error("线程池无法正常终止"); | |
| 81 | - } | |
| 82 | - } catch (InterruptedException e) { | |
| 83 | - pool.shutdown(); | |
| 84 | - Thread.currentThread().interrupt(); | |
| 85 | - } | |
| 86 | - } | |
| 87 | - | |
| 58 | + | |
| 88 | 59 | public void handle(List<GpsEntity> list) { |
| 89 | 60 | try { |
| 90 | 61 | if (list.size() == 0) |
| ... | ... | @@ -118,32 +89,7 @@ public class DataHandleProcess { |
| 118 | 89 | |
| 119 | 90 | |
| 120 | 91 | //等待子线程结束 |
| 121 | - boolean isNormal = count.await(5, TimeUnit.SECONDS); | |
| 122 | - if (!isNormal) { | |
| 123 | - try { | |
| 124 | - shutdownAndAwaitTermination(threadPool); | |
| 125 | - threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1, new ThreadFactory() { | |
| 126 | - | |
| 127 | - @Override | |
| 128 | - public Thread newThread(Runnable r) { | |
| 129 | - // TODO Auto-generated method stub | |
| 130 | - Thread t = new Thread(r); | |
| 131 | - t.setName("GPSProcessor"); | |
| 132 | - | |
| 133 | - return t; | |
| 134 | - } | |
| 135 | - | |
| 136 | - }); | |
| 137 | - //发送邮件 | |
| 138 | - EmailBean mail = new EmailBean(); | |
| 139 | - mail.setSubject("线调GPS处理"); | |
| 140 | - mail.setContent("GPS处理超时,检查线程栈文件信息<br/>"); | |
| 141 | - sendEmailController.sendMail("113252620@qq.com", mail); | |
| 142 | - logger.info("DataHandlerProcess:邮件发送成功!"); | |
| 143 | - } catch (Exception e){ | |
| 144 | - logger.error("DataHandlerProcess:邮件发送失败!",e); | |
| 145 | - } | |
| 146 | - } | |
| 92 | + count.await(); | |
| 147 | 93 | |
| 148 | 94 | //加入实时gps对照 |
| 149 | 95 | for (GpsEntity gps : list) |
| ... | ... | @@ -173,7 +119,6 @@ public class DataHandleProcess { |
| 173 | 119 | Collections.sort(list, comp); |
| 174 | 120 | GpsEntity gps; |
| 175 | 121 | for(int i = 0,len = list.size(); i< len ;i ++){ |
| 176 | - if (Thread.currentThread().isInterrupted()) break; | |
| 177 | 122 | gps = list.get(i); |
| 178 | 123 | |
| 179 | 124 | try { | ... | ... |