fix
parent
19c2e880ee
commit
31988bce68
|
@ -31,6 +31,7 @@ dependencies {
|
|||
compile("org.luaj:luaj-jse:3.0.1")
|
||||
compile("org.apache.thrift:libthrift:0.9.2")
|
||||
compile("com.alibaba:fastjson:1.2.47")
|
||||
compile("org.apache.httpcomponents:httpclient:4.5.3")
|
||||
compile files("${System.properties['java.home']}/../lib/tools.jar")
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import com.ljsd.jieling.logic.STableManager;
|
|||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||
import com.ljsd.jieling.logic.dao.MailingSystemManager;
|
||||
import com.ljsd.jieling.logic.fight.CheckFight;
|
||||
import com.ljsd.jieling.logic.fight.CombatLogic;
|
||||
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||||
import com.ljsd.jieling.netty.server.NettyGameServer;
|
||||
import com.ljsd.jieling.network.NettyProperties;
|
||||
|
@ -23,6 +22,7 @@ import com.ljsd.jieling.thread.ThreadManager;
|
|||
import com.ljsd.jieling.util.KeyGenUtils;
|
||||
import com.ljsd.jieling.util.SensitivewordFilter;
|
||||
import com.ljsd.jieling.util.TimeUtils;
|
||||
import com.ljsd.jieling.util.http.HttpPool;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
@ -32,7 +32,6 @@ import org.springframework.context.annotation.ComponentScan;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
@ -79,6 +78,8 @@ public class GameApplication {
|
|||
RedisUtil.getInstence().init(configurableApplicationContext);
|
||||
|
||||
MongoUtil.getInstence().init(configurableApplicationContext);
|
||||
//http线程池初始化
|
||||
HttpPool.init();
|
||||
|
||||
STableManager.initialize("com.ljsd.jieling.config");
|
||||
//初始化邮件
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.ljsd.jieling.config.reportData;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ljsd.common.mogodb.util.BlockingUniqueQueue;
|
||||
import com.ljsd.jieling.util.http.HttpPool;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
@ -36,13 +37,13 @@ public class DataMessageUtils {
|
|||
}
|
||||
StringBuilder info = new StringBuilder("[");
|
||||
for (int i =0 ; i < sendDataList.size() ; i++){
|
||||
if (i <= (sendDataList.size() -1)){
|
||||
if (i >= (sendDataList.size() -1)){
|
||||
info.append(sendDataList.get(i)).append(",");
|
||||
}else{
|
||||
info.append(sendDataList.get(i));
|
||||
}
|
||||
}
|
||||
info.append("]");
|
||||
System.out.println(info.toString());
|
||||
HttpPool.sendPost("",info.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package com.ljsd.jieling.config.reportData;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class TlogThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
Object take = DataMessageUtils.take();
|
||||
DataMessageUtils.manageData(take);
|
||||
}
|
||||
}
|
||||
public static void startTlogThread(){
|
||||
ExecutorService pool = Executors.newCachedThreadPool();
|
||||
for (int i = 0; i <= 5 ; i++){
|
||||
TlogThread myThread = new TlogThread();
|
||||
pool.execute(myThread);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.ljsd.jieling.thread;
|
||||
|
||||
|
||||
import com.ljsd.jieling.thread.task.DataReportTask;
|
||||
import com.ljsd.jieling.thread.task.MinuteTask;
|
||||
import com.ljsd.jieling.thread.task.PlatConfigureTask;
|
||||
import com.ljsd.jieling.thread.task.RetrySendIndicationThread;
|
||||
|
@ -23,7 +24,9 @@ public class ThreadManager {
|
|||
|
||||
|
||||
private static PlatConfigureTask platConfigureTask;
|
||||
private static DataReportTask dataReportTask;
|
||||
|
||||
public static int SLEEP_INTEVAL_TIME = 60; //每1分钟检查一次
|
||||
|
||||
private static volatile ScheduledThreadPoolExecutor scheduledExecutor; //管理task
|
||||
|
||||
|
@ -34,7 +37,7 @@ public class ThreadManager {
|
|||
public void init(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
|
||||
platConfigureTask = configurableApplicationContext.getBean(PlatConfigureTask.class);
|
||||
|
||||
dataReportTask = configurableApplicationContext.getBean(DataReportTask.class);
|
||||
go();
|
||||
}
|
||||
|
||||
|
@ -79,7 +82,10 @@ public class ThreadManager {
|
|||
// testTask 已秒为单位 延迟10s, 间隔30s为周期执行
|
||||
int delayForMinute = 60 - (now%60);
|
||||
LOGGER.info("delayForMinute---->>>>{}" ,delayForMinute);
|
||||
scheduledExecutor.scheduleAtFixedRate(platConfigureTask, 10, PlatConfigureTask.SLEEP_INTEVAL_TIME, TimeUnit.SECONDS);
|
||||
scheduledExecutor.scheduleAtFixedRate(platConfigureTask, 10, SLEEP_INTEVAL_TIME, TimeUnit.SECONDS);
|
||||
|
||||
scheduledExecutor.scheduleAtFixedRate(dataReportTask, 10, SLEEP_INTEVAL_TIME, TimeUnit.SECONDS);
|
||||
|
||||
scheduledExecutor.scheduleAtFixedRate(new MinuteTask(), delayForMinute, 60, TimeUnit.SECONDS);
|
||||
scheduledExecutor.scheduleAtFixedRate(new Thread(){
|
||||
public void run () {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package com.ljsd.jieling.thread.task;
|
||||
|
||||
import com.ljsd.jieling.config.reportData.DataMessageUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@Component
|
||||
public class DataReportTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
Object take = DataMessageUtils.take();
|
||||
DataMessageUtils.manageData(take);
|
||||
}
|
||||
}
|
||||
// public static void startTlogThread(){
|
||||
// ExecutorService pool = Executors.newCachedThreadPool();
|
||||
// for (int i = 0; i <= 5 ; i++){
|
||||
// DataReportTask myThread = new DataReportTask();
|
||||
// pool.execute(myThread);
|
||||
// }
|
||||
// }
|
||||
}
|
|
@ -12,7 +12,6 @@ import java.io.IOException;
|
|||
public class PlatConfigureTask implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PlatConfigureTask.class);
|
||||
public static int SLEEP_INTEVAL_TIME = 60; //每1分钟检查一次
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package com.ljsd.jieling.util.http;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HttpPool {
|
||||
private static PoolingHttpClientConnectionManager poolConnection = new PoolingHttpClientConnectionManager();
|
||||
private static CloseableHttpClient httpclient;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HttpPool.class);
|
||||
private static int maxSendTimes = 2;
|
||||
private static int sendIntervalTime = 200;
|
||||
public static void init(){
|
||||
poolConnection.setMaxTotal(100);
|
||||
poolConnection.setDefaultMaxPerRoute(100);
|
||||
poolConnection.setDefaultMaxPerRoute(10);
|
||||
httpclient = HttpClients.custom().setConnectionManager(poolConnection).build();
|
||||
}
|
||||
|
||||
|
||||
public static String sendPost (String url ,String info){
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
HttpResponse httpResponse;
|
||||
String retStr = "";
|
||||
int sendTimes = 0;
|
||||
try {
|
||||
httpResponse = httpclient.execute(httpPost);
|
||||
HttpEntity responseEntity = httpResponse.getEntity();
|
||||
retStr = EntityUtils.toString(responseEntity, info);
|
||||
EntityUtils.consume(responseEntity);
|
||||
int statusCode = httpResponse.getStatusLine().getStatusCode();
|
||||
if (statusCode >= 200 && statusCode <300){
|
||||
LOGGER.debug("Http Send,第" + (sendTimes + 1) + "次调用成功,返回码为:[" + statusCode + "]");
|
||||
}else{
|
||||
LOGGER.error("Http Send,第" + (sendTimes + 1) + "次调用出错,返回码为:[" + statusCode + "]");
|
||||
if (sendTimes + 1 <= maxSendTimes) {
|
||||
LOGGER.debug("Http Send," + (sendIntervalTime / 1000) + "秒后,重新发起请求...");
|
||||
try {
|
||||
Thread.sleep(sendIntervalTime);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
LOGGER.debug("Http Send,达到重发最大次数,退出程序!");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return retStr;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue