JCo3 建立连接到SAP(2)- 连接池
博客专区 > 朱君 的博客 > 博客详情
JCo3 建立连接到SAP(2)- 连接池
朱君 发表于4年前
JCo3 建立连接到SAP(2)- 连接池
  • 发表于 4年前
  • 阅读 234
  • 收藏 0
  • 点赞 0
  • 评论 0


摘要: JCo3 建立连接到SAP(2)- 连接池

import java.io.File;   
import java.io.FileOutputStream;   
import java.util.Properties;  

import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;

Configuration of destination pool and connection pooling
Each destination is associated with a connection factory and,
if the pooling feature is used, with a connection pool.
Initially the destination pool is empty. JCo runtime does not
preallocate connections. The first connection will be created
on first call. The property peak_limit describe how many
connection can be created simultaneously, if applications
allocate connections (either during a remote calls or for a
stateful call sequence) in different sessions at the same time.
After peak_limit connections are allocated (in peak_limit
sessions), the next session will wait for
maximum max_get_client_time ms until an other session
release a connection (either finishes the remote call or
ends the stateful call sequence). In case the waiting
session does not get any connection during
the max_get_client_time ms the function request will be
aborted with a JCoException with the key JCO_ERROR_RESSOURCE.
The connections that are no longer used by the applications
are put back to the internal destination pool. There are at
most pool_capacity connections kept opened by the pool. Further
connections (peak_limit-pool_capacity) will be closed immediately.
 The pooled connections (opened connection in pool) are marked as
 expired if they are not used during the expiration_time ms. The
 expired connections will be closed by a timeout checker thread,
 that runs every expiration_check_period ms.

public class ConnectPooled {
    static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";  
       Properties connectProperties = new Properties();   
        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "");   
        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "00");   
        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "000");   
        connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "TEST01");   
        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "ADMIN123");   
        connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");
        //JCO_PEAK_LIMIT -  Maximum number of idle connections kept open by the destination.
        connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");

        //JCO_POOL_CAPACITY - Maximum number of active connections that
        //can be created for a destination simultaneously
        connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,    "10");   
        createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);   

    static void createDataFile(String name, String suffix, Properties properties)   
        File cfg = new File(name+"."+suffix);   
                FileOutputStream fos = new FileOutputStream(cfg, false);   
                properties.store(fos, "for tests only !");   
            catch (Exception e)   
                throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);   
    public static void connectWithPooled() throws JCoException   
        JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);   
    public static void main(String[] args) throws JCoException   

3. 编译:

[c-sharp] view plaincopy

  1. javac -classpath  .;D:/Resources/Libraries/SAPJCo/JCO_304/sapjco3.jar -d classes ConnectPooled.java  


4. 运行:

[c-sharp] view plaincopy

  1. java -cp D:/Resources/Libraries/SAPJCo/JCO_304/sapjco3.jar;classes ConnectPooled  



[c-sharp] view plaincopy

  1. Attributes:  

  2. DEST:                  ABAP_AS_WITH_POOL  

  3. OWN_HOST:              NB-MinFei  

  4. PARTNER_HOST:          minfei  

  5. SYSTNR:                00  

  6. SYSID:                 C11  

  7. CLIENT:                000  

  8. USER:                  TEST01  

  9. LANGUAGE:              E  

  10. ISO_LANGUAGE:          EN  

  11. OWN_CODEPAGE:          1100  

  12. OWN_CHARSET:           ISO8859_1  

  13. OWN_ENCODING:          iso-8859-1  

  14. OWN_BYTES_PER_CHAR:    1  

  15. PARTNER_CODEPAGE:      1100  

  16. PARTNER_CHARSET:       ISO8859_1  

  17. PARTNER_ENCODING:      iso-8859-1  


  19. OWN_REL:               720  

  20. PARTNER_REL:           620  

  21. PARTNER_TYPE:          3  

  22. KERNEL_REL:            620  

  23. TRACE:  

  24. RFC_ROLE:              C  

  25. OWN_TYPE:              E  

  26. CPIC_CONVID:           00000000  



本节到此为止, 下节阐述如何调用JCO调用SAP Function。

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 11
博文 4
码字总数 0
作品 6
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
* 支付类型