Weblogic连接池忽略最大容量限制

时间:2018-02-06 19:32:16

标签: java oracle hibernate weblogic

在某些情况下,由于未知原因,我发现在经过一段时间(~1天)后,WL会忽略最大容量选项。

这很奇怪,因为 Pin-to-Thread 选项未选中。

WL重启或DataSorce娱乐有帮助,但仍然......可能有人面临同样的奇怪行为并找到了可接受的解决方案?

我有Oracle和Hibernate。

我正在使用 WebLogic Server版本:12.1.3.0.0

这是我的测试应用:

public class ConnectionTestServlet extends HttpServlet {
private static final Logger LOG = LoggerFactory.getLogger(ConnectionTestServlet.class);
private static int CNT = 0;

private static int successCnt = 0;
private static int failCnt = 0;

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException
{
    successCnt = 0;
    failCnt = 0;

    String dataSource = req.getParameter("ds");
    int threadCount = getValue(req, "count");
    int timeout = getValue(req, "time");
    LOG.info("CNT = [{}], TIME = [{}]", threadCount, timeout);

    for (int i = 0; i < threadCount; i++) {
        Thread worker = new Thread(() -> work(dataSource, resp, timeout));
        worker.start();
    }
}

private int getValue(HttpServletRequest req, String param) {
    String stringValue = req.getParameter(param);
    LOG.info("value = \"{}\"", stringValue);
    return stringValue == null || stringValue.equalsIgnoreCase("null") ? 0 : Integer.parseInt(stringValue);
}

private void work(String dataSourceName, HttpServletResponse resp, int timeout) {
    PrintWriter writer = null;
    Connection con = null;
    ++CNT;
    int id = CNT;
    try
    {
        LOG.info("Thread: {}", Thread.currentThread());
        writer = resp.getWriter();

        DataSource ds = getDataSource(new InitialContext(), dataSourceName);
        con = ds.getConnection();

        DatabaseMetaData metadata = con.getMetaData();
        LOG.info("url: {}", metadata.getURL());
        LOG.info("description: {}", con.toString());

        writer.append("current thread: " + Thread.currentThread());
        writer.append("\n");
        writer.append("url:").append(metadata.getURL());
        writer.append("\n");
        writer.append("description: ").append(con.toString());

        TimeUnit.SECONDS.sleep(timeout);
        successCnt++;
    }
    catch (Exception e)
    {
        failCnt++;
        LOG.error("#{} :: {}", id, e.getMessage());
    }
    finally {
        --CNT;

        LOG.info("SUCCESS: {} &&& FAIL: {}", successCnt, failCnt);

        try {
            if (con != null) con.close();
            if (writer != null)
            {
                writer.flush();
                writer.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

private DataSource getDataSource(InitialContext ctx, String name) {
    DataSource dataSource = null;
    try {
        dataSource = (DataSource) ctx.lookup(name);
        return dataSource;
    } catch (NamingException e) {
        e.printStackTrace();
    }
    return dataSource;
}
}

0 个答案:

没有答案