更新
This commit is contained in:
parent
00641af9dc
commit
fc087ef35a
@ -32,42 +32,6 @@ public class CacheManager {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取布尔值的缓存
|
|
||||||
public static boolean getSimpleFlag(String key) {
|
|
||||||
try {
|
|
||||||
return (Boolean) cacheMap.get(key);
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getServerStartdt(String key) {
|
|
||||||
try {
|
|
||||||
return (Long) cacheMap.get(key);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置布尔值的缓存
|
|
||||||
public synchronized static boolean setSimpleFlag(String key, boolean flag) {
|
|
||||||
if (flag && getSimpleFlag(key)) {// 假如为真不允许被覆盖
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
cacheMap.put(key, flag);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized static boolean setSimpleFlag(String key, long serverbegrundt) {
|
|
||||||
if (cacheMap.get(key) == null) {
|
|
||||||
cacheMap.put(key, serverbegrundt);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 得到缓存。同步静态方法
|
// 得到缓存。同步静态方法
|
||||||
private synchronized static Cache getCache(String key) {
|
private synchronized static Cache getCache(String key) {
|
||||||
return (Cache) cacheMap.get(key);
|
return (Cache) cacheMap.get(key);
|
||||||
|
78
src/main/java/osc/git/eh3/cache/SimpleCacheUtil.java
vendored
Normal file
78
src/main/java/osc/git/eh3/cache/SimpleCacheUtil.java
vendored
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package osc.git.eh3.cache;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class SimpleCacheUtil<T> {
|
||||||
|
private final Map<String, T> m_objects;
|
||||||
|
private final Map<String, Long> m_expiredObjects;
|
||||||
|
private final long m_lExpireTime;
|
||||||
|
private final ExecutorService m_executor;
|
||||||
|
|
||||||
|
public SimpleCacheUtil() {
|
||||||
|
this(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleCacheUtil(final int nExpireTime) {
|
||||||
|
m_objects = Collections.synchronizedMap(new HashMap<String, T>());
|
||||||
|
m_expiredObjects = Collections.synchronizedMap(new HashMap<String, Long>());
|
||||||
|
m_lExpireTime = nExpireTime;
|
||||||
|
m_executor = Executors.newFixedThreadPool(256);
|
||||||
|
Executors.newScheduledThreadPool(5).scheduleWithFixedDelay(RemoveExpiredObjects(), m_lExpireTime / 2, m_lExpireTime,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Runnable RemoveExpiredObjects() {
|
||||||
|
return new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
for (final String name : m_expiredObjects.keySet()) {
|
||||||
|
if (System.currentTimeMillis() > m_expiredObjects.get(name)) {
|
||||||
|
m_executor.execute(CreateRemoveRunnable(name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Runnable CreateRemoveRunnable(final String name) {
|
||||||
|
return new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
m_objects.remove(name);
|
||||||
|
m_expiredObjects.remove(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getExpireTime() {
|
||||||
|
return m_lExpireTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put(final String name, final T obj) {
|
||||||
|
put(name, obj, m_lExpireTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put(final String name, final T obj, final long expireTime) {
|
||||||
|
m_objects.put(name, obj);
|
||||||
|
m_expiredObjects.put(name, System.currentTimeMillis() + expireTime * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(final String name) {
|
||||||
|
final Long expireTime = m_expiredObjects.get(name);
|
||||||
|
if (expireTime == null)
|
||||||
|
return null;
|
||||||
|
if (System.currentTimeMillis() > expireTime) {
|
||||||
|
m_executor.execute(CreateRemoveRunnable(name));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return m_objects.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <R extends T> R get(final String name, final Class<R> type) {
|
||||||
|
return (R) get(name);
|
||||||
|
}
|
||||||
|
}
|
12
src/main/java/osc/git/eh3/cache/Test.java
vendored
12
src/main/java/osc/git/eh3/cache/Test.java
vendored
@ -3,15 +3,9 @@ package osc.git.eh3.cache;
|
|||||||
public class Test {
|
public class Test {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SimpleCache<String, Object> cache = new SimpleCache<>(5);
|
SimpleCacheUtil<Object> cache2 = new SimpleCacheUtil<>(5);
|
||||||
|
cache2.put("123", "fdfd");
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
System.out.println(cache2.get("123"));
|
||||||
cache.put(""+i, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
|
|
||||||
System.out.println(cache.get(i+""));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class TestCache {
|
public class TestCache {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println(CacheManager.getSimpleFlag("alksd"));
|
|
||||||
CacheManager.putCache("abc", new Cache("key", "value", 10, false));
|
CacheManager.putCache("abc", new Cache("key", "value", 10, false));
|
||||||
CacheManager.putCache("def", new Cache());
|
CacheManager.putCache("def", new Cache());
|
||||||
CacheManager.putCache("ccc", new Cache());
|
CacheManager.putCache("ccc", new Cache());
|
||||||
|
@ -3,7 +3,7 @@ redis.pool.maxIdle=200
|
|||||||
redis.pool.maxWait=1000
|
redis.pool.maxWait=1000
|
||||||
redis.pool.testOnBorrow=true
|
redis.pool.testOnBorrow=true
|
||||||
redis.pool.testOnReturn=true
|
redis.pool.testOnReturn=true
|
||||||
redis.ip=192.168.3.166
|
#redis.ip=192.168.3.166
|
||||||
#redis.ip=111.235.158.31
|
redis.ip=115.182.33.143
|
||||||
redis.port=7379
|
redis.port=47379
|
||||||
redis.password=
|
redis.password=
|
61
src/main/java/osc/git/eh3/test/ExecBaics50Log.java
Normal file
61
src/main/java/osc/git/eh3/test/ExecBaics50Log.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package osc.git.eh3.test;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
public class ExecBaics50Log {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
StringBuffer sb = new StringBuffer("");
|
||||||
|
|
||||||
|
FileReader reader = new FileReader("C:\\Users\\lixiangrong\\Desktop\\minisite\\20160606\\3\\2016-06-06(3、4、5).txt");
|
||||||
|
BufferedReader br = new BufferedReader(reader);
|
||||||
|
String str = null;
|
||||||
|
while ((str = br.readLine()) != null) {
|
||||||
|
String[] split = str.split(",");
|
||||||
|
String ssString = "";
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
for (String s : split) {
|
||||||
|
|
||||||
|
String substring = s.substring(s.indexOf("=") + 1);
|
||||||
|
if (substring.contains("CST")) {
|
||||||
|
substring = formatDate(substring);
|
||||||
|
|
||||||
|
|
||||||
|
ssString += "'" + substring + "'";
|
||||||
|
}else{
|
||||||
|
|
||||||
|
ssString += "'" + substring + "',";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"insert into user_info (`u_name`, `u_gender`, `u_tel`, `u_province`, `u_city`, `u_dealername`,`u_dealercode`, `u_scheduledtime`, `addtime`) VALUES("
|
||||||
|
+ ssString + ");");
|
||||||
|
}
|
||||||
|
|
||||||
|
br.close();
|
||||||
|
reader.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatDate(String date) throws Exception{
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
SimpleDateFormat sdf1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", java.util.Locale.ENGLISH);
|
||||||
|
TimeZone tz = TimeZone.getTimeZone("CST");
|
||||||
|
sdf1.setTimeZone(tz);
|
||||||
|
sdf.setTimeZone(tz);
|
||||||
|
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.setTime(sdf1.parse(date));
|
||||||
|
|
||||||
|
c.set(Calendar.HOUR, c.get(Calendar.HOUR) - 1);
|
||||||
|
return sdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
}
|
13
src/main/java/osc/git/eh3/test/Main.java
Normal file
13
src/main/java/osc/git/eh3/test/Main.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package osc.git.eh3.test;
|
||||||
|
|
||||||
|
import osc.git.eh3.redis.JedisUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by lixiangrong on 2016/6/14.
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JedisUtil.set("test_20160614","20160614");
|
||||||
|
System.out.println(JedisUtil.getStr("test_20160614"));
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,7 @@ public class TestOpenPuton {
|
|||||||
|
|
||||||
String str = "{\"order_info\":{\"order_id\":300001,\"order_name\":\"20160506Amnet\",\"brand_zh\":\"复歌Amnet\",\"brand_en\":\"fugetech\",\"note\":\"note\",\"industry\":\"个人护理/药品>护发品\",\"ad_owner\":{\"owner_id\":201,\"owner_name\":\"复歌\",\"owner_category\":\"个人护理/药品>护发品\",\"organization_code\":\"123456789\",\"website_url\":\"www.fugetech.com\",\"owner_qualification\":[{\"url\":\"http://img.pxene.com/basic/221dab14-e401-446d-bd59-5e0a798a3eb5/366f3ad4156c4625aae8202e03f1f01d.jpg\",\"qualification_name\":\"企业营业执照\"},{\"url\":\"http://img.pxene.com/basic/221dab14-e401-446d-bd59-5e0a798a3eb5/366f3ad4156c4625aae8202e03f1f01d.jpg\",\"qualification_name\":\"ICP证书\"}]},\"start_time\":\"2015-12-01\",\"end_time\":\"2016-12-30\",\"buy_type\":1,\"plat\":1,\"type\":1,\"landing_page\":\"www.fugetech.com\",\"order_area\":[{\"first_level\":\"山东\",\"second_level\":[\"烟台\",\"青岛\"]},{\"first_level\":\"河北\"}],\"order_budget\":{\"budget_all\":20000000,\"budget_day\":200000},\"order_goal\":{\"order_day_show\":200,\"order_total_show\":20000,\"order_day_click\":100,\"order_total_click\":10000,\"order_day_conversion\":50,\"order_total_conversion\":5000,\"order_day_ctr\":0.5,\"order_total_ctr\":0.5},\"order_freq\":{\"imp_day_req\":2000,\"imp_total_req\":10000,\"click_day_freq\":100,\"click_total_freq\":500},\"order_pmp\":[{\"deal_id\":123456,\"ratio\":0.12,\"purcharse\":12345,\"media_domain\":\"www.fugetech.com\"}],\"media_white\":[\"111\"],\"media_black\":[\"222\"],\"creative_group\":[{\"group_id\":1,\"group_name\":\"创意分组A\",\"landing_page\":\"www.fugetech.com\",\"impression_code\":\"www.123.com\",\"click_code\":\"www.456.com\",\"ratio\":\"40%\",\"creative\":[{\"id\":301,\"name\":\"test\",\"plat\":1,\"width\":580,\"height\":90,\"type\":\"jpg\",\"download\":true,\"url\":\"http://img.pxene.com/basic/221dab14-e401-446d-bd59-5e0a798a3eb5/366f3ad4156c4625aae8202e03f1f01d.jpg\"}]},{\"group_id\":2,\"group_name\":\"创意分组B\",\"landing_page\":\"www.fugetech.com\",\"impression_code\":\"www.789.com\",\"click_code\":\"www.963.com\",\"ratio\":\"60%\",\"creative\":[{\"id\":302,\"name\":\"test\",\"plat\":1,\"width\":580,\"height\":90,\"type\":\"jpg\",\"download\":true,\"url\":\"http://img.pxene.com/basic/221dab14-e401-446d-bd59-5e0a798a3eb5/366f3ad4156c4625aae8202e03f1f01d.jpg\"}]}]}}";
|
String str = "{\"order_info\":{\"order_id\":300001,\"order_name\":\"20160506Amnet\",\"brand_zh\":\"复歌Amnet\",\"brand_en\":\"fugetech\",\"note\":\"note\",\"industry\":\"个人护理/药品>护发品\",\"ad_owner\":{\"owner_id\":201,\"owner_name\":\"复歌\",\"owner_category\":\"个人护理/药品>护发品\",\"organization_code\":\"123456789\",\"website_url\":\"www.fugetech.com\",\"owner_qualification\":[{\"url\":\"http://img.pxene.com/basic/221dab14-e401-446d-bd59-5e0a798a3eb5/366f3ad4156c4625aae8202e03f1f01d.jpg\",\"qualification_name\":\"企业营业执照\"},{\"url\":\"http://img.pxene.com/basic/221dab14-e401-446d-bd59-5e0a798a3eb5/366f3ad4156c4625aae8202e03f1f01d.jpg\",\"qualification_name\":\"ICP证书\"}]},\"start_time\":\"2015-12-01\",\"end_time\":\"2016-12-30\",\"buy_type\":1,\"plat\":1,\"type\":1,\"landing_page\":\"www.fugetech.com\",\"order_area\":[{\"first_level\":\"山东\",\"second_level\":[\"烟台\",\"青岛\"]},{\"first_level\":\"河北\"}],\"order_budget\":{\"budget_all\":20000000,\"budget_day\":200000},\"order_goal\":{\"order_day_show\":200,\"order_total_show\":20000,\"order_day_click\":100,\"order_total_click\":10000,\"order_day_conversion\":50,\"order_total_conversion\":5000,\"order_day_ctr\":0.5,\"order_total_ctr\":0.5},\"order_freq\":{\"imp_day_req\":2000,\"imp_total_req\":10000,\"click_day_freq\":100,\"click_total_freq\":500},\"order_pmp\":[{\"deal_id\":123456,\"ratio\":0.12,\"purcharse\":12345,\"media_domain\":\"www.fugetech.com\"}],\"media_white\":[\"111\"],\"media_black\":[\"222\"],\"creative_group\":[{\"group_id\":1,\"group_name\":\"创意分组A\",\"landing_page\":\"www.fugetech.com\",\"impression_code\":\"www.123.com\",\"click_code\":\"www.456.com\",\"ratio\":\"40%\",\"creative\":[{\"id\":301,\"name\":\"test\",\"plat\":1,\"width\":580,\"height\":90,\"type\":\"jpg\",\"download\":true,\"url\":\"http://img.pxene.com/basic/221dab14-e401-446d-bd59-5e0a798a3eb5/366f3ad4156c4625aae8202e03f1f01d.jpg\"}]},{\"group_id\":2,\"group_name\":\"创意分组B\",\"landing_page\":\"www.fugetech.com\",\"impression_code\":\"www.789.com\",\"click_code\":\"www.963.com\",\"ratio\":\"60%\",\"creative\":[{\"id\":302,\"name\":\"test\",\"plat\":1,\"width\":580,\"height\":90,\"type\":\"jpg\",\"download\":true,\"url\":\"http://img.pxene.com/basic/221dab14-e401-446d-bd59-5e0a798a3eb5/366f3ad4156c4625aae8202e03f1f01d.jpg\"}]}]}}";
|
||||||
|
|
||||||
// String str = "{\"order_info\":{\"note\":\"媒体类型定向:\\nnull\\n\\n广告素材轮播:\\n平均\\n\\n\",\"put_time\":[],\"buy_type\":1,\"cost_type\":2,\"ad_owner\":{\"owner_name\":\"Fuge-test\",\"owner_category\":\"技术,媒体,通讯类>计算机服务和软件业\",\"website_url\":\"http://www.fugetech.com/\",\"owner_id\":180,\"organization_code\":null,\"owner_qualification\":[]},\"end_time\":\"2016-05-31\",\"order_budget\":{\"budget_all\":11100.0},\"landing_page\":\"www.fugetech.com\",\"industry\":\"技术,媒体,通讯类>计算机服务和软件业\",\"type\":1,\"cost_single\":100.0,\"order_name\":\"Pxene Test\",\"start_time\":\"2016-05-08\",\"order_goal\":{\"order_total_show\":111000},\"brand_zh\":\"Fuge\",\"plat\":1,\"order_id\":14578,\"brand_en\":null,\"creative_group\":[{\"group_id\":380,\"group_name\":\"test1_ttt\",\"landing_page\":\"www.123.com\",\"plat\":1,\"impression_code\":\"www.abc.com\",\"click_code\":\"www.456.com\",\"creative\":[{\"download\":true,\"name\":\"3218191555260729151.png\",\"width\":960,\"id\":653,\"type\":\"png\",\"url\":\"http://rimix.fugetech.com/sending/14578/20160509171537/creative/3218191555260729151.png\",\"height\":60}],\"ratio\":\"-\"}]}}";
|
// String str = "{\"order_info\":{\"note\":\"媒体类型定向:\\nnull\\n\\n广告素材轮播:\\n平均\\n\\n\",\"put_time\":[],\"buy_type\":1,\"cost_type\":2,\"ad_owner\":{\"owner_name\":\"Fuge-test\",\"owner_category\":\"技术,媒体,通讯类>计算机服务和软件业\",\"website_url\":\"http://www.fugetech.com/\",\"owner_id\":180,\"organization_code\":null,\"owner_qualification\":[]},\"end_time\":\"2016-05-31\",\"order_budget\":{\"budget_all\":11100.0},\"landing_page\":\"www.fugetech.com\",\"industry\":\"技术,媒体,通讯类>计算机服务和软件业\",\"type\":1,\"cost_single\":100.0,\"order_name\":\"Pxene ExecBaics50Log\",\"start_time\":\"2016-05-08\",\"order_goal\":{\"order_total_show\":111000},\"brand_zh\":\"Fuge\",\"plat\":1,\"order_id\":14578,\"brand_en\":null,\"creative_group\":[{\"group_id\":380,\"group_name\":\"test1_ttt\",\"landing_page\":\"www.123.com\",\"plat\":1,\"impression_code\":\"www.abc.com\",\"click_code\":\"www.456.com\",\"creative\":[{\"download\":true,\"name\":\"3218191555260729151.png\",\"width\":960,\"id\":653,\"type\":\"png\",\"url\":\"http://rimix.fugetech.com/sending/14578/20160509171537/creative/3218191555260729151.png\",\"height\":60}],\"ratio\":\"-\"}]}}";
|
||||||
|
|
||||||
System.out.println(HttpClientUtil.sendPostJSONData(URL, str));
|
System.out.println(HttpClientUtil.sendPostJSONData(URL, str));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user