xmc000
xmc000
无标题
2 posts
Don't wanna be here? Send us removal request.
xmc000 · 3 years ago
Text
常见Error以及Exception
常见Error以及Exception
RuntimeException
NullPointerException - 空指针引用异常
ClassCastException - 类型强制转换异常
IllegalArgumentException - 传递非法参数异常
IndexOutOfBoundsException - 下标越界异常
NumberFormatException - 数字格式异常::试图将String转换为数字类型,但是字符串不满足数字格式要求的时候。
非RuntimeException
ClassNotFoundException - 找不到指定class的异常
IOException - IO操作异常
Error
NoClassDefFoundError - 找不到class定义的异常::成因1.类依赖的class或者jar不存在2.类文件存在,但是存在不同的域中(对应的class在javaclasspath中不可用,或者有多个不同类加载器重复加载了同一个class)3.大小写问题,javac编译的时候是无视大小写的,很有可能编译出来的class文件就与想要的不一致。
StackOverflowError - 深递归导致栈被耗尽而抛出的异常
OutOfMemoryError - 内存溢出异常
0 notes
xmc000 · 4 years ago
Text
Redis pipe example for java
Redis pipe example
import org.joda.time.DateTime; import redis.clients.jedis.Jedis; import redis.clients.jedis.Pipeline; import redis.clients.jedis.Response; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.*; import java.util.stream.Stream; public class RedisBatchVal { public static void main(String[] args) throws IOException { Jedis jedis = new Jedis(); jedis.select(1); pipe(jedis); iptop(jedis); } private static void pipe(Jedis jedis) throws IOException { HashMap<String, Integer> map = inputBatchKey(); long startTime = System.currentTimeMillis(); //获取开始时间 Pipeline pipe = jedis.pipelined(); Map<String, Response<String>> newMap = new HashMap<>(); for (Map.Entry<String, Integer> entry : map.entrySet()) { newMap.put(entry.getKey(), pipe.get(entry.getKey())); } pipe.sync(); long endTime = System.currentTimeMillis(); //获取结束时间 System.out.println(MainApp.getCurrentThreadName() + new DateTime().toString("yyyy-MM-dd HH:mm:ss") + "程序运行时间:" + (endTime - startTime) + "ms"); //输出程序运行时间 HashMap<String, Integer> tempMap = new HashMap<>(); for (Map.Entry<String, Response<String>> stringResponseEntry : newMap.entrySet()) { Response<String> value = stringResponseEntry.getValue(); String key = stringResponseEntry.getKey(); Integer integer = Integer.valueOf(value.get()); tempMap.put(key, integer); } sort(tempMap); } private static HashMap<String, Integer> inputBatchKey() throws IOException { HashMap<String, Integer> map = new HashMap<>(); try (Stream<String> lines = Files.lines(Paths.get("/Users/xmc/IdeaProjects/cron-ftp/src/main/resources/a.txt"), Charset.defaultCharset())) { lines.forEach(key -> { map.put(key, null); }); } return map; } private static void iptop(Jedis jedis) throws IOException { HashMap<String, Integer> map = inputBatchKey(); long startTime = System.currentTimeMillis(); //获取开始时间 Map<String, Integer> treeMap = new HashMap(); for (Map.Entry<String, Integer> entry : map.entrySet()) { String key = entry.getKey(); treeMap.put(entry.getKey(), Integer.valueOf(jedis.get(key))); } long endTime = System.currentTimeMillis(); //获取结束时间 System.out.println(MainApp.getCurrentThreadName() + new DateTime().toString("yyyy-MM-dd HH:mm:ss") + "程序运行时间:" + (endTime - startTime) + "ms"); //输出程序运行时间 sort(treeMap); } private static void sort(Map<String, Integer> treeMap) { List<Map.Entry<String, Integer>> list_Data = new ArrayList<Map.Entry<String, Integer>>(treeMap.entrySet()); Collections.sort(list_Data, (o1, o2) -> { if ((o2.getValue() - o1.getValue()) > 0) return 1; else if ((o2.getValue() - o1.getValue()) == 0) return 0; else return -1; }); } }
1 note · View note