zoukankan      html  css  js  c++  java
  • 单例模式范例

     1 package util;
     2 import org.web3j.protocol.geth.Geth;
     3 import org.web3j.protocol.http.HttpService;
     4 
     5 public class GethClientUtil {
     6 
     7     private volatile static Geth geth;
     8 
     9     public static Geth getClient() {
    10         if (geth == null) {
    11             synchronized (GethClientUtil.class) {
    12                 if (geth == null) {
    13                     try {
    14                         geth = Geth.build(new HttpService(PropUtil.getProps().getProperty("RPC_ADDR")));
    15                     } catch (Exception e) {
    16                         e.printStackTrace();
    17                     }
    18                 }
    19             }
    20         }
    21         return geth;
    22     }
    23 
    24 }

     配置文件工具类

     1 package util;
     2 
     3 import java.io.InputStream;
     4 import java.util.Properties;
     5 
     6 public class PropUtil {
     7 
     8     private static Properties props = null;
     9     
    10     static {
    11         readProperties("ether.properties");
    12     }
    13     
    14     private static void readProperties(String fileName) {    
    15         try {    
    16             props = new Properties();
    17             InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
    18             props.load(inputStream);
    19             inputStream.close();
    20         } catch (Exception e) {    
    21             e.printStackTrace();    
    22         }    
    23     } 
    24     
    25     public static Properties getProps() {
    26         return props;
    27     }
    28     
    29 }

    配置文件

    1 #调用RPC地址
    2 RPC_ADDR=http://127.0.0.1:8545
    3 #矿工费参数
    4 GAS_PRICE=22000000000
    5 GAS_LIMIT=4300000
    6 #私钥文件存储路径
    7 KEYSTORE_PATH=E:/Project/TestGeth/keystore
  • 相关阅读:
    JS之函数声明与表达式
    任重道远!
    Java_Notes01
    Android_Application Fundamentals
    Android_Activity
    Android
    Linux下的实模式和保护模式
    spring注解原理
    开启aix SFTP日志 是否和链接SFTP有关呢
    Apache版本兼容性问题
  • 原文地址:https://www.cnblogs.com/guanghe/p/8984271.html
Copyright © 2011-2022 走看看