eclipse生成webservice客户端高并发客户端调用-发送报文出现重复问题处理

通用客户端实现方案-eclipse生成WebService客户端以及使用https://blog.csdn.net/u014677702/article/details/85070833WebService

eclipse生成webservice客户端高并发客户端调用-发送报文出现重复问题处理


package com.hand.wbs.ws.service.test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

import org.apache.axis.AxisFault;

import com.hand.wbs.ws.service.FileInfo;
import com.hand.wbs.ws.service.FileInfoGetLocator;
import com.hand.wbs.ws.service.FileInfoGetSoapBindingStub;


public class RunningTaskWorker implements Runnable {
    
    private FileInfo fileInfo;
    private String endpoint;
    
    private CountDownLatch latch;
    
    private Map<String, String> map;
    
    public RunningTaskWorker(String endpoint,FileInfo fileInfo, CountDownLatch latch,
        Map<String, String> map) {
        this.fileInfo = fileInfo;
        this.latch = latch;
        this.map = map;
        this.endpoint = endpoint;
    }
    
    public void run() {
        try {
            FileInfoGetSoapBindingStub stub = null;
            try {
                URL endpointURL = new URL(endpoint);
                stub = new FileInfoGetSoapBindingStub(endpointURL, new FileInfoGetLocator());
            } catch (AxisFault | MalformedURLException e) {
                e.printStackTrace();
            }
            
            if (null == stub) {
                System.out.println("接口初始化错误");
                return;
            }
            
            System.out.println("开始发报文:" + fileInfo.getFileNm());
            
            stub.ordinaryMsg(fileInfo);
            //System.out.println("完成发报文:" + fileInfo.getFileNm());
        } catch (Exception e) {
            if (!e.getMessage().endsWith("org.xml.sax.SAXException: Bad envelope tag:  service")) {
                e.printStackTrace();
                map.put(fileInfo.getFileNm(), fileInfo.getFileNm());
               // System.out.println("发生异常1:" + e.getMessage());
            } else {
                //System.out.println("完成发报文:" + fileInfo.getFileNm());
            }
        } catch (Throwable e) {
            if (!e.getMessage().endsWith("org.xml.sax.SAXException: Bad envelope tag:  service")) {
                e.printStackTrace();
                map.put(fileInfo.getFileNm(), fileInfo.getFileNm());
               // System.out.println("发生异常1:" + e.getMessage());
            } else {
                //System.out.println("完成发报文:" + fileInfo.getFileNm());
            }
        } finally {
            latch.countDown();// 线程完成任务,计数器减一
        } // end catch
    }
}
 

问题原因,多线程高并发出现线程间资源不安全问题出现导致发报文重复:

根本原因是:FileInfoGetSoapBindingStub stub = new FileInfoGetSoapBindingStub(endpointURL, new FileInfoGetLocator()); 线程不安全,必须确保每次发送报文new一个响应的接口对象,才能解决重复报文问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值