File tree 1 file changed +19
-4
lines changed
1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -306,7 +306,7 @@ gas limit 是gas price的基础上 你最多愿意出多少份,也就是说gas
306
306
Credentials credentials = Credentials .create (privateKey );
307
307
308
308
EthGetTransactionCount ethGetTransactionCount = web3j .ethGetTransactionCount (
309
- from, DefaultBlockParameterName .LATEST ).sendAsync (). get ();
309
+ from, DefaultBlockParameterName .LATEST ).send ();
310
310
311
311
BigInteger nonce = ethGetTransactionCount .getTransactionCount ();
312
312
@@ -650,9 +650,24 @@ allowance 两个参数_owner ,_spender 查询剩余的_owner 授权给_sp
650
650
同步就是要等待处理完才继续执行,如先approve再进行transferFrom,如果使用异步就可能出问题,还没授权成功就进行交易,这样首先不会成功,而且gas price * gas limit会被全吞,本文使用的全都是send(),这样会带来一个问题,接口等待时间太长,响应无效了,处理方式如下
651
651
调用上链操作时异步执行
652
652
653
- Async.run(() ->
654
- proxyTranUsdt(address,address,num)
655
- );
653
+ // 异步执行上链
654
+ // 两个线程的线程池
655
+ ExecutorService executor = Executors.newFixedThreadPool(2);
656
+ //jdk1.8的实现方式
657
+ CompletableFuture<String> future = CompletableFuture.supplyAsync(new Supplier<String>() {
658
+ @Override
659
+ public String get() {
660
+ System.out.println("task started!");
661
+ try {
662
+ proxyTranUsdt(address,address,num) ;
663
+ } catch (Exception e) {
664
+ e.printStackTrace();
665
+ }
666
+ return "task finished!";
667
+ }
668
+ }, executor);
669
+ //采用lambada的实现方式
670
+ future.thenAccept(e -> System.out.println(e + " ok"));
656
671
657
672
## 15.分享一下我的上链记录class
658
673
You can’t perform that action at this time.
0 commit comments