Config.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.pbsage.util;
  2. import java.io.File;
  3. import java.net.URLDecoder;
  4. import org.dom4j.Document;
  5. import org.dom4j.Element;
  6. import org.dom4j.io.SAXReader;
  7. public class Config {
  8. public static String json_file;
  9. public static int thread_count_ini;
  10. public static int thread_count_add;
  11. public static int thread_count_max;
  12. public static int loop_count;
  13. public static long interval_loop;
  14. public static long interval_step;
  15. public static int job_count;
  16. static {
  17. try {
  18. {
  19. String filepathDatabase = Constant.GetPath() + "/config.xml";
  20. SAXReader saxReader = new SAXReader();
  21. File xmlFile = new File(URLDecoder.decode(filepathDatabase, "UTF-8"));
  22. Document document = saxReader.read(xmlFile);
  23. Element element;
  24. element = (Element) document.selectSingleNode("/root/json_file");
  25. json_file = element.getText();
  26. element = (Element) document.selectSingleNode("/root/thread_count_ini");
  27. thread_count_ini = Integer.parseInt(element.getText());
  28. element = (Element) document.selectSingleNode("/root/thread_count_add");
  29. thread_count_add = Integer.parseInt(element.getText());
  30. element = (Element) document.selectSingleNode("/root/thread_count_max");
  31. thread_count_max = Integer.parseInt(element.getText());
  32. element = (Element) document.selectSingleNode("/root/loop_count");
  33. loop_count = Integer.parseInt(element.getText());
  34. element = (Element) document.selectSingleNode("/root/interval_loop");
  35. interval_loop = Long.parseLong(element.getText());
  36. element = (Element) document.selectSingleNode("/root/interval_step");
  37. interval_step = Long.parseLong(element.getText());
  38. element = (Element) document.selectSingleNode("/root/job_count");
  39. job_count = Integer.parseInt(element.getText());
  40. }
  41. } catch (Exception e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. }